﻿// --- Cookie handler --------------------------------------------------------- //

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value + expires + ";domain=.blue-line.dk";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function checkLoginCookie() {
  var loginCookie = readCookie('loginCookie');
  createCookie('loginCookie','',-1);

  if(loginCookie) {
    var url = loginCookie;
    
    document.location = url;
  }
}

// --- Flyt snippet fra sitelayout --------------------------------------------------------- //

function MoveSnippet(sCon, nsCon) {
var SnippetContainer = document.getElementById(sCon);
var NewSnippetContainer = document.getElementById(nsCon);

   if (SnippetContainer && NewSnippetContainer) {
     Tangora.DOM.MoveElement(sCon, nsCon);
     SnippetContainer.style.display = "block";
   }
}

function LoadHandler()
{
  MoveSnippet('mergefield_navigation_level2','NewSnippetContainer1');

  //MoveSnippet('page-20000003_columnset13_column1','NewSnippetContainer2');
  //MoveSnippet('page-20000004_columnset2_column1','NewSnippetContainer2');
  //MoveSnippet('page-20000005_columnset7_column1','NewSnippetContainer2');
  //MoveSnippet('page-20000006_columnset2_column1','NewSnippetContainer2');
  //MoveSnippet('page-20000007_mergefield_-20000029','NewSnippetContainer2');

  //MoveSnippet('page-20000013_columnset3_column1','NewSnippetContainer2');
  //MoveSnippet('page-20000014_columnset3_column1','NewSnippetContainer2');
  //MoveSnippet('page-20000015_columnset2_column1','NewSnippetContainer2');
  //MoveSnippet('page-20000016_columnset2_column1','NewSnippetContainer2');

  Tangora.Layout.Resize();
}


 // --- Slet standart indhold på input felt ved klik -------------------------------------- //

function clearText(thefield){
  if (thefield.defaultValue==thefield.value)
  thefield.value = ""
} 



 // --- Tilføj til foretrukne -------------------------------------- //

function bookmark(title) {
  var url = document.location;
  if (window.sidebar) {
    window.sidebar.addPanel(title,url);
  }
  else if(window.external) {
    window.external.AddFavorite(url,title); 
  }
  else if(window.opera && window.print) {
  }
}




 // --- Produktkonfigurator -------------------------------------- //
//Tilføjet af TS-MSO d. 20-11-2008

function NameSpace() {}

function xImageArchive(mainElmId, thumbElmId)
{
	this.MainImage = null;
	this.Thumbnails = null;
	this.Debug = false;

	this.Init = function()
	{
		var mainImageWrapper = document.getElementById(mainElmId);
		if(!mainImageWrapper)
		{
			if(this.Debug) window.alert("MainImageWrapper with ID \"" + mainElmId + "\" not found.");
			return;
		}

		this.MainImage = mainImageWrapper.getElementsByTagName("img")[0];
		if(!this.MainImage)
		{
			if(this.Debug) window.alert("MainImage not found.");
			return;
		}

		this.ThumbImageWrapper = document.getElementById(thumbElmId);
		if(!this.ThumbImageWrapper)
		{
			if(this.Debug) window.alert("ThumbImageWrapper with ID \"" + thumbElmId + "\" not found.");
			return;
		}

		this.ThumbNails = this.ThumbImageWrapper.getElementsByTagName("img");

		//Attach handlers
		this.MainImage.onclick = this.MainImageClickHandler;
		for(var i = 0; i < this.ThumbNails.length; i++)
		{
			this.ThumbNails[i].Archive = this;
			this.ThumbNails[i].onclick = this.ThumbImageClickHandler;
			if(i==0) this.ThumbNails[i].className = "active";
		}
	}

	this.MainImageClickHandler = function()
	{
		var orgSrc = this.src.replace("/thumbs","");
		orgSrc = orgSrc.replace(location.protocol + "//" + location.host,"");
		var w = window.open("/page111.aspx?imgpath=" + orgSrc,"Visbillede","width=500,height=500,toolbars=no");
	}

	this.ThumbImageClickHandler = function()
	{
		var activeElm = Tangora.DOM.GetFirstCollectionMemberByClassName(this.Archive.ThumbImageWrapper,"img","active");
		if(activeElm) activeElm.className = "";

		this.Archive.MainImage.src = this.src;
		this.className = "active";
	}
}

function xConfigurator(confElmId, priceElmId, textElmId, myConfElmId, pricegroup)
{
	this._pageURL = "";
	this.DisplayAsPlainText = false;

	this.ConfiguratorWrapper = null;
	this.TextPriceWrapper = null;
	this.PriceWrapper = null;
	this.TextWrapper = null;
	this.ConfigurationWrapper = null;

	this.UserID = "";
	this.ConfigurationName = "";
	this.CustomConfigurationName = "";
	this.ConfigurationRecID = 0;
	this.ConfigurationID = "";
	this.ConfigurationPrice = 0;
	this.ConfigurationStandardPrice = 0;
	this.IsDraft = "";

	this.OverrideStandardSelection = false;
	this.SelectedComponents = "";
	
	this.Debug = true;

	this.Init = function()
	{
		this.ConfiguratorWrapper = document.getElementById(confElmId);
		this.PriceWrapper = document.getElementById(priceElmId);
		this.TextPriceWrapper = document.getElementById("text-" + priceElmId);
		this.TextWrapper = document.getElementById(textElmId);
		this.ConfigurationWrapper = document.getElementById(myConfElmId);
		this.Render();
		this.SelectComponents();
		this.InitialPriceSetup();
		this.InitialComponentTypeSetup();
		if(!this.DisplayAsPlainText) this.UpdatePrice();
		this.CancelWaitBox();
	}

	this.CancelWaitBox = function()
	{
		var elm = document.getElementById("wait-box");
		if(elm) elm.style.display = "none";
	}

	this.SelectComponents = function()
	{
		if(this.OverrideStandardSelection)
		{
			var compArr = this.SelectedComponents.split(",");

			for(var i = 0; i < compArr.length; i++)
			{
				var chk = document.getElementById("component-radio-" + compArr[i]);
				if(chk) chk.checked = true;
			}
		}
	}

	this.InitialPriceSetup = function()
	{
		var checkBoxes = Tangora.DOM.GetCollectionByClassName(this.ConfiguratorWrapper,"input","component-radio");
		
		for(var i = 0; i < checkBoxes.length; i++)
		{
			var cId = checkBoxes[i].id.replace("component-radio-","");
			var cTypeId = checkBoxes[i].name.replace("component-type-","");
			var cItemId = document.getElementById("component-item-id-" + cId).value;
			var cPrice = document.getElementById("component-price-" + cId).value;
			if(cPrice == "") cPrice = 0;
			var standard = document.getElementById("component-standard-" + cId).value;

			checkBoxes[i].ComponentID = cId;
			checkBoxes[i].ComponentTypeID = cTypeId;
			checkBoxes[i].ComponentItemID = cItemId;
			checkBoxes[i].ComponentPrice = cPrice;
			checkBoxes[i].Configurator = this;
			checkBoxes[i].IsStandard = (standard == "checked");
			checkBoxes[i].onclick = this.RadioClickHandler;

			var iPriceElm = document.getElementById("initial-component-standard-price-" + cTypeId);
			var sPriceElm = document.getElementById("component-standard-price-" + cTypeId);
			var cPriceElm = document.getElementById("component-price-" + cId);

			if(checkBoxes[i].IsStandard && checkBoxes[i].checked)
			{
				sPriceElm.value = (cPriceElm.value == "") ? 0 : cPriceElm.value;
				iPriceElm.value = sPriceElm.value;			
			}
			else if(checkBoxes[i].IsStandard)
			{
				iPriceElm.value = (cPriceElm.value == "") ? 0 : cPriceElm.value;
			}
			else if(checkBoxes[i].checked)
			{
				sPriceElm.value = (cPriceElm.value == "") ? 0 : cPriceElm.value;
			}
		}
	}

	this.InitialComponentTypeSetup = function()
	{
		var cTypes = Tangora.DOM.GetCollectionByClassName("configurator-wrapper","div","component-type-wrapper");

		if(!this.DisplayAsPlainText)
		{
			var ul = document.createElement("ul");
			ul.id = "myconfiguration-list";
		}

		for(var i = 0; i < cTypes.length; i++)
		{
			var cTypeId = cTypes[i].id.replace("component-type-","");
			this.SetComponentPricesForType(cTypeId);

			if(!this.DisplayAsPlainText)
			{
				var li = document.createElement("li");
				li.id = "myconfiguration-item-" + cTypeId;
				li.innerHTML = this.GetSelectedComponentText(cTypeId);
/* Edit start */

				if(li.innerHTML == '') { li.style.display='none'; }

				if(li.firstChild)
				{
					if(li.firstChild.innerHTML == 'Ingen') { li.style.display='none'; }
					if(li.firstChild.innerHTML == 'Basiskonfiguration') { li.style.display='none'; }
				}

/* Edit slut */
				ul.appendChild(li);
			}
		}

		if(!this.DisplayAsPlainText) this.ConfigurationWrapper.appendChild(ul);
	}

	this.GetSelectedComponentText = function(cTypeId)
	{
		var items = Tangora.DOM.GetCollectionByClassName("component-type-" + cTypeId,"input","component-radio");

		var txt = "";

		for(var i = 0; i < items.length; i++)
		{
			if(items[i].checked)
			{
				txt = this.GetComponentText(items[i].ComponentID);
			}
		}

		return txt;
	}

	this.GetComponentText = function(cId)
	{
		var wrap = document.getElementById("component-item-" + cId);
		var elm = wrap.getElementsByTagName("label");
		return elm[0].innerHTML;
	}

	this.UpdateMyConfigurationElement = function(confTypeId,text)
	{
		var activeElm = Tangora.DOM.GetFirstCollectionMemberByClassName(this.ConfigurationWrapper,"li","last-changed");
		if(activeElm) activeElm.className = "";

		var elm = document.getElementById("myconfiguration-item-" + confTypeId);

		if(elm)
		{
/* Edit start */
			elm.style.display='';
			if(text == '') { elm.style.display='none'; }
			if(text == '<span class="section">Ingen</span>') { elm.style.display='none'; }
			if(text == '<span class="section">Basiskonfiguration</span>') { elm.style.display='none'; }
			if(text == '<SPAN class=section>Ingen</SPAN>') { elm.style.display='none'; }
			if(text == '<SPAN class=section>Basiskonfiguration</SPAN>') { elm.style.display='none'; }
/* Edit slut */
			elm.innerHTML = text;
			elm.className = "last-changed";
		}

		Tangora.Layout.Resize();
	}

	this.SetComponentPricesForType = function(typeId)
	{
		var checkBoxes = Tangora.DOM.GetCollectionByClassName("component-type-" + typeId,"input","component-radio");
		var standardPrice = document.getElementById("component-standard-price-" + typeId).value;

		for(var i = 0; i < checkBoxes.length; i++)
		{
			var compPrice = document.getElementById("component-price-" + checkBoxes[i].ComponentID).value;
			if(compPrice == "") compPrice = 0;

			var diffPriceTxt = "";
		
			if(checkBoxes[i].checked)
			{
				var diffPriceTxtVariable = '';

				if(document.getElementById('configurator-text-wrapper')==null) { diffPriceTxtVariable = 'Standard'; }

				diffPriceTxt = '<i>' +diffPriceTxtVariable+ '</i>';
			}
			else
			{
				var diffPrice = (parseInt(compPrice)-parseInt(standardPrice));
				diffPriceTxt = BlueLine.ProductConfigurator.AddThousandDelimiters(diffPrice) + ",-";

				if(diffPrice > 0) diffPriceTxt = "+" + diffPriceTxt;
			}

			var priceWrap = document.getElementById("component-price-wrapper-" + checkBoxes[i].ComponentID);
			if(priceWrap) priceWrap.innerHTML = diffPriceTxt;
		}
	}

	this.RadioClickHandler = function()
	{
		var compPrice = document.getElementById("component-price-" + this.ComponentID).value;
		document.getElementById("component-standard-price-" + this.ComponentTypeID).value = (compPrice == "") ? 0 : compPrice;
		this.Configurator.SetComponentPricesForType(this.ComponentTypeID);
		this.Configurator.UpdatePrice();
		this.Configurator.UpdateMyConfigurationElement(this.ComponentTypeID,this.Configurator.GetComponentText(this.ComponentID));
	}

	this.Render = function()
	{
		if(!this.ConfiguratorWrapper)
		{
			if(this.Debug) window.alert("ConfiguratorWrapper not found");
			return;
		}

		if(!this.DisplayAsPlainText)
		{	
			if(!this.TextPriceWrapper)
			{
				if(this.Debug) window.alert("TextPriceWrapper not found");
				return;
			}

			if(!this.PriceWrapper)
			{
				if(this.Debug) window.alert("PriceWrapper not found");
				return;
			}

			if(!this.TextWrapper)
			{
				if(this.Debug) window.alert("TextWrapper not found");
				return;
			}

			if(!this.ConfigurationWrapper)
			{
				if(this.Debug) window.alert("ConfigurationWrapper not found");
				return;
			}
		}

		if(this._pageURL == "")
		{
			if(this.Debug) window.alert("PageURL not set");
			return;
		}

		if(pricegroup) {
		    var html = tsAjax.innerHTML(this._pageURL + "&rndkey=" + Math.random(10) + "&pricegroup=" + pricegroup);
		} else {
							     var html = tsAjax.innerHTML(this._pageURL + "&rndkey=" + Math.random(10));
							}

		this.ConfiguratorWrapper.innerHTML = html;
	}

	this.SetPageURL = function(strLink)
	{
		this._pageURL = strLink.replace("<a href='/page109","/page110").replace("'>pageurl</a>","");
	}

	this.UpdatePrice = function()
	{
		var checkBoxes = Tangora.DOM.GetCollectionByClassName("configurator-wrapper","input","component-radio");

		var extraPrice = 0.00;

		for(var i = 0; i < checkBoxes.length;i++)
		{
			if(checkBoxes[i].checked && !checkBoxes[i].IsStandard)
			{
				var standardPrice = document.getElementById("initial-component-standard-price-" + checkBoxes[i].ComponentTypeID).value;

				var compPrice = document.getElementById("component-price-" + checkBoxes[i].ComponentID).value;
				if(compPrice == "") compPrice = 0;
				extraPrice += parseFloat(compPrice);
				extraPrice = extraPrice - parseFloat(standardPrice);
			}
		}

		this.ConfigurationPrice = (parseFloat(this.ConfigurationStandardPrice) + extraPrice);
		this.PriceWrapper.value = this.ConfigurationPrice;
		this.TextPriceWrapper.innerHTML = BlueLine.ProductConfigurator.FormatNumber(this.ConfigurationPrice);
	}

	this.SaveConfigurationClickHandler = function()
	{
		this.IsDraft = "";
		this.CustomConfigurationName = this.ConfigurationName;
		
		this.SaveCurrentConfiguration(true);
	}

	this.DialogSaveConfigurationDraftClickHandler = function(name, cId, overwrite)
	{
		if(name != "" && name != null)
		{
			this.IsDraft = "1";
			this.CustomConfigurationName = name;
			if(cId != "" && cId > 0 && overwrite) this.ConfigurationId = cId;
			this.SaveCurrentConfiguration(false);
		}
	}

	this.SaveConfigurationDraftClickHandler = function()
	{
		var url = "/saveconfiguration";
		var cId = BlueLine.RequestQuerystring("configurationid");
		var cName = BlueLine.RequestQuerystring("configurationname");
		if(cName == null || cName == "") cName = encodeURIComponent("Min konfiguration");
		url += "?configurationame=" + cName;
		if(cId != null && cName != null) url += "&configurationid=" + cId;
		
		var w = window.open(url,"SaveConfiguration","width=300,height=150,toolbars=no");

		//this.IsDraft = "1";
		//var name = window.prompt("Indtast venligst navnet på konfigurationen:","Min konfiguration");
		//if(name != "" && name != null)
		//{
			//this.CustomConfigurationName = name;
			//this.SaveCurrentConfiguration(false);
		//}
	}

	this.SaveCurrentConfiguration = function(addToBasket)
	{
		var cTxt = "<table border='0' cellpadding='0' cellpadding='0' class='component-table'>";
		var xmlTxt = "<components>";

		var wraps = Tangora.DOM.GetCollectionByClassName(this.ConfiguratorWrapper,"div","component-type-wrapper");

		for(var i = 0; i < wraps.length; i++)
		{
			var chks = Tangora.DOM.GetCollectionByClassName(wraps[i],"input","component-radio");

			for(var x = 0; x < chks.length; x++)
			{
				if(chks[x].checked && chks[x].ComponentID != "")
				{
					var cTypeId = chks[x].ComponentTypeID;
					var cTypeName = Tangora.DOM.GetFirstCollectionMemberByClassName(wraps[i],"h3","component-header").innerHTML;
					var cStandardPrice = parseFloat(document.getElementById("initial-component-standard-price-" + cTypeId).value);

					var cId = chks[x].ComponentID;
					var cName = "";
					var cPrice = "";		

					cTxt += "<tr class='component-row'>";
					cTxt += "<td class='component-cell-header'>" + cTypeName + "</td>";
					cTxt += "<td class='component-cell-name'>" + this.GetComponentText(cId) + "</td>";
					cTxt += "</tr>";

					xmlTxt += "<component>";
					xmlTxt += "<itemid>" + chks[x].ComponentItemID + "</itemid>";
					xmlTxt += "<amount>1</amount>";
					xmlTxt += "<price>" + chks[x].ComponentPrice + "</price>";
					xmlTxt += "<difference>" + (parseFloat(chks[x].ComponentPrice)-cStandardPrice) + "</difference>"
					xmlTxt += "</component>";
				}
			}
		}

		cTxt += "</table>";
		cTxt = cTxt.replace(/'/gi,"\"");
		xmlTxt += "</components>";

		var comps = this.GetSelectedComponents();

		var strRes = "ErKonfiguration=1&ErGemtKonfiguration=" + this.IsDraft + "&Komponenter=" + comps;
		strRes += "&Varenr_=" + this.ConfigurationID + "&Pris=" + this.ConfigurationPrice.toString();
		strRes += "&Konfiguration=" + this.ConfigurationRecID + "&Komponent_tekst=" + encodeURIComponent(cTxt) + "&XMLKomponenter=" + xmlTxt;
		strRes += "&Varenavn=" + this.CustomConfigurationName + "&BrugerID=" + this.UserID;

		var url = location.protocol + "//" + location.host+ "/page115.aspx?action=post&layoutid=1";
		if(this.ConfigurationId != "" && this.ConfigurationId > 0) url += "&listid=-300000&recid=" + this.ConfigurationId;

		var storage = tsAjax.createInstance("bgsave");
		storage.method="post";
		storage.postData = strRes + "&previouscontent=";
		if(addToBasket) storage.callback = this.SaveCurrentConfigurationCallback;
		tsAjax.innerHTML(url,'tsAjax',"bgsave");
	}

	this.GetSelectedComponents = function()
	{
		var elms = Tangora.DOM.GetCollectionByClassName("configurator-wrapper","input","component-radio");
		var comps = "";		

		for(var i = 0; i < elms.length; i++)
		{
			if(elms[i].checked)
			{
				comps += elms[i].ComponentID + ",";
			}
		}

		comps = comps.substring(0,comps.length-1);

		return comps;
	}

	this.SaveCurrentConfigurationCallback = function(amount)
	{
		if (this.ajaxObj!=null) {
			if (this.ajaxObj.readyState==4)
			{
				var RT = this.ajaxObj.responseText;
				RT = RT.replace("<!-- Blankt layout start -->","").replace("<!-- Blankt layout end -->","");

						var num = document.getElementById("number");
						
						var am = 1;
						if(num) am = num.value;
						if(isNaN(am)) am = 1;

				BlueLine.ProductConfigurator.AddToBasket(RT,am);

				if (this.statusElement!=null) {this.statusElement.innerHTML = this.statusText_Done;}
				if (this.resultElement!=null) {this.resultElement.innerHTML = RT}
			}			
		}
		else
		{
			var RT = this.IF.innerHTML;
			if (this.statusElement!=null) {this.statusElement.innerHTML = this.statusText_Done;}
			if (this.resultElement!=null) {this.resultElement.innerHTML = RT}
		}
	}

	this.SendConfigurationClickHandler = function(srcPageId, destPageId, recId,skjultepriser)
	{
		if(skjultepriser == undefined) { var skjultepriser = ''; }
		var url = "/page" + srcPageId + ".aspx?pid=" + destPageId + skjultepriser + "&rid=" + recId + "&components=" + this.GetSelectedComponents();
		document.location = url;
	}

	this.checkLogin = function(pid,rid)
	{
		if(rid !== '')
		{
			var loginKnap = document.getElementById('user_-1');
			var logudKnap = document.getElementById('logud');
			loginKnap.onclick = function() {
				var url = 'http://shopbasket.blue-line.dk/page' +pid+ '.aspx?recordid' +pid+ '=' +rid+ '&components=' +pc.GetSelectedComponents();
				createCookie('loginCookie',url,1);
			}
			logudKnap.onclick = function() {
				var url = 'http://shopbasket.blue-line.dk/page' +pid+ '.aspx?recordid' +pid+ '=' +rid+ '&components=' +pc.GetSelectedComponents();
				createCookie('loginCookie',url,1);
				document.location='http://shopbasket.blue-line.dk/default.aspx?id=52&action=logout&redirpage=' +pid+ '&clearcookie=1';
			}
		}
	}

}

function xComponentTypeClickHandler(url)
{
	if(url == "") return;
	var w = window.open(url,"componenttypeinfo","width=516,height=500,resizeable=no,toolbars=no,scrollbars=yes");
}

function xRoundNumber(num, dec)
{
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function xFormatNumber(num, excludeCurr)
{
	var numStr = "";
	num = num.toString().replace(",",".");

	numStr = BlueLine.ProductConfigurator.RoundNumber(num,0);

	if(numStr > 999)
	{
		numStr = BlueLine.ProductConfigurator.AddThousandDelimiters(numStr);	
	}

	numStr = numStr.toString();
	if(!excludeCurr) numStr = "Kr. " + numStr;
	numStr = numStr + ",-";

	return numStr;
}

function xAddThousandDelimiters(num)
{
	num = num.toString();

	while (num.match(/^-?\d\d{3}/))
	{
		num = num.replace(/(\d)(\d{3}(\.|,|$))/, '$1\.$2');
	}
	
	return num;
}


function xAddToBasket(productid,count)
{
	URL='/page63.aspx?isbasket=1&pageid=63&listid=-300003&action=add&closeatonce=1&productid='+productid+'&count='+count;
	
	   if (document.getElementById ('MiniBasketPageId'))
	{
		URL=URL+'&minibasket=2&minibasketpageid='+document.getElementById ('MiniBasketPageId').innerHTML+'&rnd='+RandomName(4);
	}
	tsAjax.innerHTML(URL,'tsAjax','default',null,null,BlueLine.ProductConfigurator.AddToBasketDone);
}

function xAddToBasketDone()
{
	if (tsAjax.storage['default'].ajaxObj.readyState==4)
	{
		if (document.getElementById ('MiniBasketPageId'))
		{
			var obj=document.getElementById ('MiniBasketFrame');
			obj.src='page'+document.getElementById ('MiniBasketPageId').innerHTML+'.aspx?isbasket=1&pageid='+document.getElementById ('MiniBasketPageId').innerHTML+'&listid=-300003&minibasketbgload=1&rnd='+RandomName(4);
		}
	}
}

function xRQ(name)
{
	var qs = window.location.search.substring(1);
	var qsArr = qs.split("&");

	for (var i=0; i<qsArr.length; i++)
	{
		var ft = qsArr[i].split("=");
		if (ft[0] == name) return ft[1];
	}
}

function FormatContentsAsNumber()
{
	var mm = document.getElementById("mergefield_main");
	if(!mm) return;

	var elms = Tangora.DOM.GetCollectionByClassName("mergefield_main","div","formatContentsAsNumber");

	for(var i = 0; i < elms.length; i++)
	{
		var srcElm = (elms[i].childNodes.length > 0 && elms[i].childNodes[0].tagName != null) ? elms[i].childNodes[0] : elms[i];

		var val = srcElm.innerHTML.replace(",-","").replace(",",".");
		
		val = BlueLine.ProductConfigurator.RoundNumber(val,0);
		val = BlueLine.ProductConfigurator.AddThousandDelimiters(val);
				elms[i].innerHTML = val.toString() + ",-";
/* Edit start */
		if(val == '0' && srcElm.title == 'oversigtdataark') {
				srcElm.parentNode.firstChild.innerHTML=' ';
				srcElm.innerHTML=' ';
		}
		if(val == '0' && srcElm.title == 'oversigtkonfigurator') {
				srcElm.parentNode.firstChild.innerHTML=' ';
				srcElm.innerHTML=' ';
		}
/* Edit slut */
	}
}

Tangora.Events.AddHandler(window,"onload",FormatContentsAsNumber);

var BlueLine = new NameSpace();
BlueLine.ProductConfigurator = new NameSpace();
BlueLine.ProductConfigurator.ImageArchive = xImageArchive;
BlueLine.ProductConfigurator.Configurator = xConfigurator;
BlueLine.ProductConfigurator.ComponentTypeClickHandler = xComponentTypeClickHandler;
BlueLine.ProductConfigurator.FormatNumber = xFormatNumber;
BlueLine.ProductConfigurator.RoundNumber = xRoundNumber;
BlueLine.ProductConfigurator.AddToBasket = xAddToBasket;
BlueLine.ProductConfigurator.AddToBasketDone = xAddToBasketDone;
BlueLine.ProductConfigurator.AddThousandDelimiters = xAddThousandDelimiters;
BlueLine.RequestQuerystring = xRQ;

function NumberKeyDownHandler(e)
{
  var keyCode = (e.which) ? e.which : window.event.keyCode;

  if(keyCode == 13)
  {
    var wrap = document.getElementById("leag-i-kurv-knap");
    var a = wrap.getElementsByTagName("a")[0];
    a.onclick();
    return false;
  }
}


function ManipulateSearchForm(siteId)
{
  var frm = null;
  var newItemNameControlName = "";
  var newItemCategoryControlName = "";

  //Tilføj en case for hvert site - og tilpas de respektive værdier
  switch(siteId)
  {

    //Portal site
    case 2:
	   //Formular
	frm = document.forms.rediger191;
	
	   //Nye kontrol navne
	newItemNameControlName = "filtercontrol1331";
	newItemCategoryControlName = "filtercontrol1332";

	   //Formular manipulation
	   frm.action = "/page133.aspx";
	frm.getElementsByTagName("input")[0].name = "doshow133";
	break;

    //Digital skiltning
    case 3:
	   //Formular
	frm = document.forms.rediger521;
	
	   //Nye kontrol navne
	newItemNameControlName = "filtercontrol5221";
	newItemCategoryControlName = "filtercontrol5222";

	   //Formular manipulation
	   frm.action = "/page522.aspx";
	frm.getElementsByTagName("input")[0].name = "doshow522";
	break;

    //Rugged Mobile Computers
    case 4:
	   //Formular
	frm = document.forms.rediger589;
	
	   //Nye kontrol navne
	newItemNameControlName = "filtercontrol5371";
	newItemCategoryControlName = "filtercontrol5372";

	   //Formular manipulation
	   frm.action = "/page537.aspx";
	frm.getElementsByTagName("input")[0].name = "doshow537";
	break;

    //Industrial Computers & Displays
    case 5:
	   //Formular
	frm = document.forms.rediger655;
	
	   //Nye kontrol navne
	newItemNameControlName = "filtercontrol6061";
	newItemCategoryControlName = "filtercontrol6062";

	   //Formular manipulation
	   frm.action = "/page606.aspx";
	frm.getElementsByTagName("input")[0].name = "doshow606";
	break;

  }

  //Standardværdier (Ikke ændre noget herunder)
  var url = document.location.href;
  var params = url.substring(url.indexOf("?"));
  var paramArr = params.split('&');
  
  var itemName = "";
  var catId = "";

  if(paramArr.length > 2)
  {
    itemName = paramArr[1].split('=')[1];
    catId = paramArr[2].split('=')[1];
  }

  var itemNameControl = frm.getElementsByTagName("input")[1];
  var itemCatControl = frm.getElementsByTagName("select")[0];

  itemNameControl.name = newItemNameControlName;
  itemCatControl.name = newItemCategoryControlName;

  if(itemName == "")
  {
    itemNameControl.value = "Varenavn"
    frm.onclick = function() { 
	if(itemNameControl.value == 'Varenavn')
	  itemNameControl.value='';
    }
  }
  else
    itemNameControl.value = itemName;

  for(var i = 0; i < itemCatControl.options.length; i++)
  {
    var opt = itemCatControl.options[i];

    if(i == 0)
	opt.innerHTML = "Vælg kategori";

    opt.selected = (opt.value == catId);
  }

}
