﻿/*
DICTIONARY CODE
*/

// Function to registrer events
function addEvent(element, eventname, func) {
	if(window.addEventListener) {    
		if (eventname=="onclick") {eventname="click"}
		if (eventname=="onload") {eventname="load"}
		element.addEventListener(eventname, func, false);
	} else if (element.attachEvent) {
		element.attachEvent(eventname, func)
	}
}

// Dictionary initial variables
var InitDictionary=true; // needs to be true
var DictionaryPageID="{system.page.id}"; // This is the currentpage id

// Custom dictionary variables
popupPageId=77;  // The pageid of the list page that is used to display the information for the word (in a popup window)
var linkClass="dictionarylink";  // The typography class used to wrap the words
var linkPrefix="ORDBOG: "; // The prefix displayed before the word in the "title text"
var popupWindowWidth=350; 
var popupWindowHeight=300; // notice: window is automatically resized...
var popupWindowLeft=500;
var popupWindowTop=150;

document.write("<scri"+"pt type='text/javascript' src='/html/ordbog/dictionary.js'></scr"+"ipt>");
document.write("<scri"+"pt type='text/javascript' src='/DictionaryTerms'></scr"+"ipt>");

// Register the CreateDictionaryLinks function this way instead of the default window.load, to avoid concurrency problemns
addEvent(window, "onload", DoInitDictionary);

function DoInitDictionary() {
CreateDictionaryLinks();
}










// START SHOP IFRAME SCRIPT - EVISION/JENS
  function ShopIframe(Id,Path,Style)
  {
    this.TangoraUrl = window.location.href.split('/');
    this.Domain = this.TangoraUrl[2].replace('www.','');
    this.ShopUrl = 'http://shop.'+this.Domain+Path;

    this.Create = function ()
    {
	document.writeln('<iframe id=\"'+Id+'\" name=\"'+Id+'\" style=\"'+Style+'\" onload=\"return SF.Size();\" src=\"'+this.ShopUrl+'\" frameborder=\"0\" scrolling=\"no\"></iframe>');
    }

    this.Size = function ()
    {
	try
	{
	  document.domain = this.Domain;
	  var FrameObj = null;
	  // if contentDocument exists, W3C compliant (Mozilla)
	  if (document.getElementById(Id).contentDocument)
	    FrameObj = document.getElementById(Id).contentDocument;
	   // else Internet Explorer
	  else
	    FrameObj = document.frames[Id].document;
	  var ShopHeight = FrameObj.body.scrollHeight + 50;
	  document.getElementById(Id).style.height = ShopHeight;
	}
	catch(E)
	{
	  var ErrorMsg = (document.all) ? E.message : E;
	  var Msg = 'Problem med browserindstillingerne!\nKlik OK for at blive stillet videre til siden.\n\nFejlmeddelse: '+ErrorMsg;
	  if (confirm(Msg) == true)
	  {
	    var ShopWindow = window.open(this.ShopUrl,'','');
	    if (ShopWindow == null)
		alert('Pop-up vinduet blev blokeret!');
	  }
	  else
	    window.location.href = this.TangoraUrl[0]+this.TangoraUrl[1];
	}
    }
  }
  // END SHOP IFRAME SCRIPT

function AddItemToBasket(itemID)
{
	var num = document.getElementById("number_textbox");
	if (!num) num = document.getElementById("number_textbox_" + itemID);
	var size = document.getElementById("size_select");
	var numval = 1;

	if(num) numval = num.value;

	if(size) itemID = size.options[size.selectedIndex].value;

	AddToBasket(itemID,numval);

	return false;
}

function VarietyHandler(priceContainerID, destContainerID, destContainerRowID)
{
	this.Items = new Array();
	this.PriceContainer = document.getElementById(priceContainerID);
	var destContainer = document.getElementById(destContainerID);
	var destRow = document.getElementById(destContainerRowID);

	this.Add = function(intID,strName,intPrice,intSalePrice)
	{
		var o = new Object();
		o.id = intID;
		o.name = strName;
		o.intPrice = intPrice;
		o.intSalePrice = intSalePrice;
		this.Items.push(o);
	}

	this.SetPrice = function(i)
	{
		var price = this.Items[i].intPrice;

		if(parseFloat(this.Items[i].intSalePrice) > 0)
		{
			price += "<span class='sale_price'> - Tilbud: " + this.Items[i].intSalePrice + "</span>";
		}

		this.PriceContainer.innerHTML = price;		
	}

	this.OnChangeHandler = function()
	{
		var i = this.selectedIndex;
		vHandler.SetPrice(i);
	}

	this.Render = function()
	{
		if(this.Items.length > 0)
		{
			var select = document.createElement("select");
			select.id = "size_select";
			select.onchange = this.OnChangeHandler;

			for(var i = 0; i < this.Items.length; i++)
			{
				var option = document.createElement("option");
				option.value = this.Items[i].id;
				option.innerHTML = this.Items[i].name;
				select.appendChild(option);
			}

			this.SetPrice(0);
			destContainer.appendChild(select);
			destRow.style.display = "block";
		}
	}
}

function CopyValue(source, target)
{
	this.SourceElement = null;
	this.TargetElement = null;

	this.Init = function()
	{
		cv.SourceElement = document.getElementById(source);
		cv.TargetElement = document.getElementById(target);

		cv.SourceElement.onblur = cv.OnBlurHandler;
	}

	this.Copy = function()
	{
		this.TargetElement.value = this.SourceElement.value;

	}

	this.OnBlurHandler = function()
	{
		cv.Copy();
	}
}
