﻿ function DisplayLink(link, file, icon)
{
  var linkStr = "";

  if(link != "") linkStr = link;
  else if(file != "") linkStr = file;

  if(linkStr != "") document.write("<a href=\"" + linkStr + "\" target=\"_blank\"><img src=\"/media/" + icon + "\" alt=\"Link\" style=\"border:none;\" /></a>");
}

function centerLayout()
{
  var ws = new windowSize();
  wWidth = ws.Width;
  wHeight = ws.Height;

  var layout = document.getElementById("sitelayout4");
  if(!layout) layout = document.getElementById("sitelayout5");
  lWidth = layout.clientWidth;
  lHeight = layout.clientHeight;

  var margin = (wHeight-lHeight)/2;
  if(margin > 0) layout.style.marginTop = margin + "px";
}
//Tangora.Events.AddHandler(window,"onload",centerLayout);
//Tangora.Events.AddHandler(window,"onresize",centerLayout);

function windowSize()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  var object = new Object();
  object.Width = myWidth;
  object.Height = myHeight;
  return object;
}

function manipulateLinks(strId, curPageId)
{
	var spans = Tangora.DOM.GetCollectionByClassName(strId,"span","button-orglink");

	for(var i = 0; i < spans.length; i++)
	{
		var vLink = spans[i].parentNode.getElementsByTagName("a")[0];
		var hLink = spans[i].getElementsByTagName("a")[0];
		if(hLink != null)
		{
		  vLink.href = hLink.href;
			  var href = vLink.href.substring(0,vLink.href.lastIndexOf("."));
			  
			  if(curPageId != null && !isNaN(curPageId))
			  {
			    var pageId = parseInt(href.substring(href.lastIndexOf(".")+1));
			    curPageId = parseInt(curPageId);

			    if(pageId == curPageId) vLink.parentNode.className += " active";
			  }
			}
	}
}


function verticalCenterNavigation(strId, handler)
{
  if(handler) handler();
  //var elms = Tangora.DOM.GetCollectionByClassName(strId,"li","navigationlistitem");
  var source = document.getElementById(strId);
  if(!source) return;
  var elms = source.getElementsByTagName("li");

  for(var i = 0; i < elms.length; i++)
  {
    var li = elms[i];

    if(!li) return;
    var a = li.getElementsByTagName("a")[0];
    if(!a) return;
    var height = a.clientHeight;
    var span = a.getElementsByTagName("span")[0];
    if(!span) return;
    span.style.height = "auto";

    var paddingTop = Math.round((height-span.clientHeight)/2);
    var paddingBottom = paddingTop;

    if((paddingTop + paddingBottom + span.clientHeight)>height) paddingBottom--;

    span.style.padding = paddingTop + "px 0px " + paddingBottom + "px 0px";
  }
}

function MoviePlayer(width, height)
{
	this.ID = "Afspiller";
	this.Type = "video/quicktime";
	this.Width = width;
	this.Height = height;
	this.Scale = "scale";
	this.ClassId = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
	//this.Standby = "Loader Windows Media Player...";
	this.CodeBase = "http://www.apple.com/qtactivex/qtplugin.cab";
	this.Cache = "1";
	this.BufferingTime = "5";

	   var link = "";

	   this.Show = function(linkstr)
	   {
		  link = linkstr;
		  document.write("<span id=\"movieph\"></span>");
		  Tangora.Events.AddHandler(window,"onload",function(){video.RealShow.call(video);});
	   }
		this.RealShow = function()
		{
		var mask = /href\=['"](.*?)['"]/;
		var re = new RegExp(mask);
		var m = re.exec(link);

		if(!m)
		{
			document.write("File not found");
			return;
		}
		
		var ob;
		
		if(Tangora.Browser.IE)
		{
			ob = document.createElement("afspiller");
			ob.id = this.ID;
			ob.type = this.Type;
			if(width > 0) ob.width = this.Width;
			if(height > 0) ob.height = this.Height;
			ob.classid = this.ClassId;
			ob.standby = this.Standby;
			ob.codebase = this.CodeBase;
			ob.cache = this.Cache;
			ob.bufferingtime = this.BufferingTime;
				   ob.scale = this.Scale;

			var par = document.createElement("param");
			//par.name = "filename";
			par.name = "src";
			par.value = m[1] + "&action=show";
			ob.appendChild(par);

			var par = document.createElement("param");
			//par.name = "autostart";
			par.name = "autoplay";
			par.value = "true";
			ob.appendChild(par);

			var par = document.createElement("param");
			par.name = "type";
			par.value = this.Type;
			ob.appendChild(par);

			var par = document.createElement("param");
			par.name = "scale";
			par.value = this.Scale;
			ob.appendChild(par); 

		}
		else
		{
			ob = document.createElement("embed");
			ob.id = this.ID;
			ob.type = this.Type;
			if(width > 0) ob.width = this.Width;
			if(height > 0) ob.height = this.Height;
			ob.src = m[1] + "&action=show";
			ob.autoplay = "true";
			   ob.pluginspage = "http://www.apple.com/quicktime/download/";
			  ob.setAttribute("scale","scale");
		}

		   var wrap = document.createElement("span");
		wrap.appendChild(ob);

		//document.write(wrap.innerHTML.replace(/afspiller/gi,"object"));
			var cont = document.getElementById("movieph");
			cont.innerHTML = wrap.innerHTML.replace(/afspiller/gi,"object");

	}
}

function showProductDetails()
{
  showLayer('detail-layer');

  var imgWrap = document.getElementById("module10_1_columnset8_column1");
  var img = imgWrap.getElementsByTagName("img")[0];
  var txtWrap = document.getElementById("module10_1_columnset6_column1");
  var txtElm = Tangora.DOM.GetFirstCollectionMemberByClassName(txtWrap,"div","vdcontent");
  var txt = txtElm.innerHTML;

  var newWrap = document.createElement("div");
  newWrap.style.cursor = "pointer";
  newWrap.onclick = function() {hideLayer('detail-layer');moveImg()};
  var newImg = document.createElement("div");
  var newTxt = document.createElement("div");

  newWrap.id = "newWrapper";
  newImg.id = "newImageWrapper";
  newTxt.id = "newTxtWrapper";

  newImg.appendChild(img);
  newTxt.innerHTML = txt;
  
  newWrap.appendChild(newImg);
  newWrap.appendChild(newTxt);

  var dLayer = document.getElementById("detail-layer");
  dLayer.insertBefore(newWrap,dLayer.childNodes[0]);

  Tangora.Layout.Resize();
}

function moveImg() {
  var imgWrap = document.getElementById("newImageWrapper");
  var img = imgWrap.getElementsByTagName("img")[0];

  var newWrapper = document.getElementById("module10_1_columnset8_column1");
  var newImgWrap = Tangora.DOM.GetFirstCollectionMemberByClassName(newWrapper,"div","vdcontent");
  var span = newImgWrap.getElementsByTagName("span")[0];
  span.appendChild(img);

  var dLayer = document.getElementById("detail-layer");
  dLayer.removeChild(dLayer.childNodes[0]);
}

function showLayer(strId)
{
  var layer = document.getElementById(strId);
  if(layer) layer.style.display = "block";
}

function hideLayer(strId)
{
  var layer = document.getElementById(strId);
  if(layer) layer.style.display = "none";
}

function BrowserCheck()
{
  if((Tangora.Cookies.GetCookieValue("tangora","browsercheck")!="done") && Tangora.Browser.IE && Tangora.Browser.Version.indexOf("6.") > -1)
  {
    Tangora.Cookies.SetCookieValue("tangora","browsercheck","done");
    window.alert("This website is designed for Internet Explorer 7+ - please update your web browser for the best result");
  }
}

function GetRecordIds(typeId)
{
  var html = tsAjax.innerHTML("/page91.aspx?tid=" + typeId + "&rnd=" + Math.random(10000));
  var regEx = /<span id="pageid-wrapper">((\d+,?)+),<\/span>/gi;  
  var nextRecordId = 0;

  var captures = regEx.exec(html);
  
  html = captures[1];

  var htmlArr = html.split(',');

  return htmlArr;
}

function GetNavigationText(typeId, recordId)
{
  var ids = GetRecordIds(typeId);
  var length = ids.length;
  
  for(var i = 1; i <= ids.length; i++)
  {
    if(parseInt(ids[i]) == parseInt(recordId))
    {
	break;
    }
  }

  if(i > length) i = 0;

  document.write("<div class='navigation-text'>" + (i+1) + "/" + length + "</div>");
}

function GetNextPageLink(typeId, recordId, pageId)
{
  var htmlArr = GetRecordIds(typeId);
  var nextRecordId = 0;
  for(var i = 0; i < htmlArr.length; i++)
  {
    if(parseInt(recordId) == parseInt(htmlArr[i]))
    {
	var nextIndex = ((i+1)>= htmlArr.length) ? 0 : i+1;
	nextRecordId = htmlArr[nextIndex];
	break;
    }
  }

  var linkHtml = GetPagingLink(pageId, "<img src='/media/forward.gif' alt='' border='none'>", nextRecordId);
  document.write(linkHtml);
}

function GetPreviousPageLink(typeId, recordId, pageId)
{
  var htmlArr = GetRecordIds(typeId);
  var previousRecordId = 0;
  for(var i = 0; i < htmlArr.length; i++)
  {
    if(parseInt(recordId) == parseInt(htmlArr[i]))
    {
	var previousIndex = ((i-1) <= 0) ? (htmlArr.length-1) : i-1;

	previousRecordId = htmlArr[previousIndex];
	break;
    }
  }

  var linkHtml = GetPagingLink(pageId, "<img src='/media/back.gif' alt='' border='none'>", previousRecordId);
  document.write(linkHtml);
}

function GetPagingLink(pageId, innerHTML, recId)
{
   return "<a href='/page"+pageId+".aspx?recordid"+ pageId +"=" + recId + "'>"+innerHTML+"</a>";
}

function InsertNavigationText(pageId, pageTitle)
{
  if(pageId != 4 && pageId != 28) return;

  var nav = document.getElementById("navigationlistitem_" + pageId);
  if(!nav) return;
  var span = nav.getElementsByTagName("span")[0];
  if(!span) return;
  span.innerHTML = pageTitle + "<br/><font style='color:white;'>" + span.innerHTML + "</font>";
}
Tangora.Events.AddHandler(window,"onload",BrowserCheck);