var ajax_xmlhttp_city = null;

/* pleasure slidedowns */
//var arrVirkSoegCached = new Array();
if (typeof jQuery != 'undefined')  {
	jQuery(document).ready(function(){
		jQuery(".mTeaserSliders a.teaser").hover(
			function(){
				if(jQuery("span",this).queue("fx").length < 2) {
		  			jQuery("span",this).slideDown(300);
				}
			},
			function(){
				jQuery("span",this).slideUp(300);
			}
		);
	
		// on click, toggle a slide and the class name of the parent. 
		jQuery("div.personalNewslist .settings h3").click(function(){
			jQuery(this).next().slideToggle().parent().toggleClass("settingsExpanded");
		}).css("cursor","pointer");
		
		
		jQuery("div.personalNewslist .settings :checkbox").click(function(){
			if (this.checked && this.value == "alle"){
				jQuery("div.personalNewslist .settings :checkbox:enabled").not(jQuery(this)).check('on');
			}
			else if (!this.checked && this.value == "alle") {
				jQuery("div.personalNewslist .settings :checkbox:enabled").not(jQuery(this)).check('off');
			}
			else if (!this.checked){
				jQuery("div.personalNewslist .settings :checkbox[value='alle']:checked").check('off');
			}
		});
		
		jQuery('.mMostRead ul.tab li a').click(function () {
			var that = jQuery(this);
			that.parent().addClass('active').siblings().removeClass('active');
			that.parent().parent().next().find('ul').hide().end().find('.articles'+ that.attr('class')).show();
			return false;
   		 });
		
		jQuery('.s5SoegVirksomhed form').submit(function() {
			var form = jQuery(this),
				results = jQuery('.ac_results');
			form.find('input').blur();
			if(results.css('display') == 'block') {
				var url = results.find('.ac_over').attr('id');
				document.location = (form.hasClass('urlpart')) ? '?urlpart_firm='+ url : url;
			}
			return false;	
		});
		
		jQuery('.jQuerySoegVirksomhed').blur().val('Indtast virksomhed').focus(function(){ if (jQuery(this).val()== "Indtast virksomhed") jQuery(this).val(""); })
			.blur(function(){ if (jQuery(this).val()== "") jQuery(this).val("Indtast virksomhed");})
			.autocomplete("/services/ajax/ajax_s5_soeg_virksomhed.php",{
				selectFirst: true,
				delay: 200,
				cacheLength: 10,
				formatItem: function(item){
					return item[0];
				}
			}).result(function(event, item) {
				location.href = item[1];
			});
			
		
			
		jQuery('.jQuerySoegVirksomhedDebat').blur().val('Vælg aktie').focus(function(){ if (jQuery(this).val()== 'Vælg aktie') jQuery(this).val(""); })
			.blur(function(){ if (jQuery(this).val()== "") jQuery(this).val('Vælg aktie');})
			.autocomplete("/services/ajax/ajax_s5_soeg_virksomhed.php",{
				selectFirst: true,
				delay: 200,
				cacheLength: 10,
				formatItem: function(item){
					return item[0];
				}
			}).result(function(event, item) {
				document.getElementById("instid").value = item[2];
				//location.href = item[1];
			});
			//return false;

		// open links in a new browser-windows, if the classname "openInNewWindow" is present
		jQuery('a.openInNewWindow').click(function(){
			window.open(this);
			return false;
		});
	
		 
		generateClicks();
	
		jQuery(".a25_quickpoll .reply, .pollList .reply ").click(function() {
			var dl = jQuery(this).parent().prev(),
				pollId = dl.attr('id').replace('pollId','');
				answerId = dl.find('input:checked').attr('class');	
			pollVote(pollId, answerId, dl);
			return false;
		});
		// trader pro virksomheds søgning (SME)
		jQuery('.jQueryTraderSoegVirksomhedSme').blur().val('Indtast virksomhed').focus(function(){ if (jQuery(this).val()== "Indtast virksomhed") jQuery(this).val(""); })
			.blur(function(){ if (jQuery(this).val()== "") jQuery(this).val("Indtast virksomhed");})
			.autocomplete("/services/ajax/ajax_trader_soeg_virksomhed.php?type=sme",{
				selectFirst: true,
				delay: 200,
				cacheLength: 10,
				formatItem: function(item){
					return item[0];
				}
			}).result(function(event, item) {
				location.href = "?urlpart_firm="+item[1];		// reload samme side med "?urlpart_firm="+item[1]
			});
		

		// trader pro virksomheds søgning (Nyheder)
		jQuery('.jQueryTraderSoegVirksomhedNews').blur().val('Indtast virksomhed').focus(function(){ if (jQuery(this).val()== "Indtast virksomhed") jQuery(this).val(""); })
			.blur(function(){ if (jQuery(this).val()== "") jQuery(this).val("Indtast virksomhed");})
			.autocomplete("/services/ajax/ajax_trader_soeg_virksomhed.php?type=news",{
				selectFirst: true,
				delay: 200,
				cacheLength: 10,
				formatItem: function(item){
					return item[0];
				}
			}).result(function(event, item) {
				location.href = "?urlpart_firm="+item[1];		// reload samme side med "?urlpart_firm="+item[1]
			});
			
		// trader pro headline funktion (Nyheder)
		jQuery('div.mainDouble div.column1 div.a6Firm .backLink').parent().parent().find('div.blueboxgenma, div.a6Firm h1').hide();
		
		jQuery('div.mSearchCompany a').click(function(){
			jQuery(this).parent().parent().find('div.listResult').toggleClass('listResultActive');
		});
		
		// calculate online units price
		jQuery('.onlineUnits input').keyup(function(){
			var amount = jQuery(this);
			var price = (isNaN(amount.val())) ? "0" : amount.val() * amount.prev().val();
			var allPrices = 0;
			
			jQuery('.onlineUnits table input[type="text"]').each(function(){
				var inp = jQuery(this);
				if (!isNaN(inp.val())){
					allPrices += inp.val()*inp.prev().val();
				}
			});
			amount.parent().next().text(price + ' kr');
			jQuery('.onlineUnits .total .price').text(allPrices + ' kr');
		});
		
		zipCodeStreeName.init();
	});
  
  var zipCodeStreeName = {
    init: function() {
      var $subCountry = jQuery('select#subCountry');
      if(!$subCountry.length) {
        this.bind();
      } else {
        if($subCountry.val() === 'DK') {
          this.bind();
        }
        $subCountry.change(function() {
          if($subCountry.val() === 'DK') {
            zipCodeStreeName.bind();
          } else {
            zipCodeStreeName.unbind();
          }
        });
      }
    },
    bind: function() {
      // set autocomplete on streetname input fields, but not until the zipcode have been set.
  		jQuery(".jQstreetname").autocomplete("/services/ajax/ajax_lookup_address.php", {
  			cacheLength:0,
  			delay: 600,
  			extraParams: {
  				zipcode: function() {
  					return jQuery(".jQzipcode").val()
  				}
  			}
  		});    

      // set autocomplete on city from zipcode.
  		jQuery('.jQzipcode').blur(function() {

  			jQuery.ajax({
  			   type: "GET",
  			   url: "/services/ajax/ajax_lookup_city.php",
  			   data: "zipcode=" + jQuery(".jQzipcode").val() + "",
  			   success: function(msg){

  			   		var cityField = document.getElementById('subCity');
  			   		if(cityField) {
  			   			cityField.value = msg;
  			   		}
  			   }
  			});
  		});
    },
    unbind: function() {
      jQuery('input.jQzipcode, input.jQstreetname').unbind();
    }
  };
}

// initialize variable for Børsen Web Player
var iScrolling;

// put all intializing scripts here
function init() {
	setEvents(); // put events on elements
	moveScrollbar('scrollMarker','playerPlaylistInner')
	correctMenuSize();
//	setLeftMenu();
	flashTvPlaylistEvents(); // set events on the Flash TV playlist items
//	setWmode()
}

function setLeftMenu(){
	var links = document.getElementById('myPages').getElementsByTagName('a');
	for(var i = 0;i < links.length;i++) {
		if(links[i].className == 'active') {
			showMyPagesMenu();
			break;
		}
	}
}

function showMyPagesMenu(){
	var oBox = document.getElementById("menuBox");
	if (!oBox) oBox = document.getElementById("menuBoxMy");
		var oTab1 = oBox.getElementsByTagName("li")[0];
		var oTab2 = oBox.getElementsByTagName("li")[1];
	menuChange(2,oTab1,oTab2);
}

function framePrint() {
	window.print();
}

function refreshObject(){
	var oMovie = document.getElementById("playerMovie");
	if (oMovie){
		oMovie.outerHTML = oMovie.outerHTML;
	}
}
// if not IE, remove all the fancy buttons and go for the standard player look
function playerExtensions(){
	oControls = document.getElementById("playerControls");
	oControls2 = document.getElementById("playerControls2");
	oMovie = document.getElementById("playerMovie").getElementsByTagName("object")[0];

	if (oControls && oMovie){
		if (document.all){
			oControls.style.display = "block";
			if (oControls2){ oControls2.style.display = "none";
			}
		} else {
			if (oControls2) {
				oControls.style.display = "none";
				oControls2.style.display = "block";
			}
			oMovieEmbed = oMovie.getElementsByTagName("embed")[0];
			oMovie.style.display = "block";
			oMovieEmbed.style.display = "block";

			oMovie.style.height = (oMovie.clientHeight+70)+"px";
			oMovieEmbed.style.height = (oMovie.clientHeight)+"px";
		}
	}
}

function checkplayersize(){
	var oObj = document.getElementById("player1");
	if (oObj.offsetWidth > 400){
		oObj.style.height = (400/(oObj.offsetWidth/(oObj.offsetHeight-72)))+72;
		oObj.style.width = "400px";
	}
}

// sets scrolling to true/false
function scrollStatus(iActive){
	iScrolling = iActive;

	if (iActive == 0){
		var oImg1 = document.getElementById("scrollerUp");
		var oImg2 = document.getElementById("scrollerDown");

		if (oImg1.src.substring(0,(oImg1.src.lastIndexOf("_over"))))
			oImg1.src = oImg1.src.substring(0,(oImg1.src.lastIndexOf("_over")))+".gif";
		if (oImg2.src.substring(0,(oImg2.src.lastIndexOf("_over"))))
			oImg2.src = oImg2.src.substring(0,(oImg2.src.lastIndexOf("_over")))+".gif";
	}
}

// set events on elements
function setEvents(){
	var oMove1 = document.getElementById("scrollerUp");
	var oMove2 = document.getElementById("scrollerDown");
	var oScroller = document.getElementById("scrollMarker");
	var oBox = "playerPlaylistInner";
	var oBody = document.getElementsByTagName("body")[0];
	oBoxDiv = document.getElementById(oBox);

	if (oBoxDiv){
		if (oBoxDiv.scrollHeight > oBoxDiv.offsetHeight){ // sæt events hvis der er flere elementer end der kan blive vist
			oScroller.style.display = "block"
			// set mousedown events
			oMove1.onmousedown = function (){ scrollElement(oBox,5,0); }
			oMove2.onmousedown = function (){ scrollElement(oBox,5,1); }

			// set mouseup events
			oMove1.onmouseup = function (){ scrollStatus(0); setTimeout("scrollStatus(1); scrollElement('" + oBox + "',1,0);",0060); }
			oMove2.onmouseup = function (){ scrollStatus(0); setTimeout("scrollStatus(1); scrollElement('" + oBox + "',1,1);",0060); }

			// set mouseover events
			oMove1.onmouseover = function (){ if (iScrolling != 2){scrollStatus(1); scrollElement(oBox,1,0);} }
			oMove2.onmouseover = function (){ if (iScrolling != 2){scrollStatus(1); scrollElement(oBox,1,1);} }

			// set mouseout events
			oMove1.onmouseout = function (){  if (iScrolling != 2){scrollStatus(0);} }
			oMove2.onmouseout = function (){  if (iScrolling != 2){scrollStatus(0);} }

			// set scrollbar events
		//	oScroller.onmousemove = function (oEvent) { vertScroll(this,oEvent); }
			oScroller.onmousedown = function () { scrollStatus(2); }

			// set body mouseup events
			oBody.onmousemove = function (oEvent) { if (vertScroll){vertScroll(oScroller,oEvent,oBox);} }
			oBody.onmouseup = function (){ scrollStatus(0); }
		}
		else {
			oScroller.style.display = "none";
		}
	}
}



// flyt viewet i feltet
function scrollElement(sObj,iSpeed,iDirection){
	if (iScrolling == 1){ // if scrolling is set to true
		var oObj = document.getElementById(sObj);
		var oImg1 = document.getElementById("scrollerUp");
		var oImg2 = document.getElementById("scrollerDown");

		if (iDirection == 0 && oObj.scrollTop > 0){ // scrolling upwards
			oObj.scrollTop = oObj.scrollTop - iSpeed;
			if (!oImg1.src.substring(0,(oImg1.src.lastIndexOf("_over")))){
				oImg1.src = oImg1.src.substring(0,(oImg1.src.lastIndexOf(".")))+"_over.gif";
			}
		}
		else if (iDirection == 1 && oObj.scrollTop < oObj.scrollHeight){ // scrolling downwards
			oObj.scrollTop = oObj.scrollTop + iSpeed;
			if (!oImg2.src.substring(0,(oImg2.src.lastIndexOf("_over")))){
				oImg2.src = oImg2.src.substring(0,(oImg2.src.lastIndexOf(".")))+"_over.gif";
			}
		}

		moveScrollbar("scrollMarker",sObj);
		setTimeout("scrollElement('" + sObj + "'," + iSpeed + "," + iDirection + ");",0050);
	}
}
// flyt scrollbaren i henhold til playlisten
function moveScrollbar(sObj,sObj2){
	oObj = document.getElementById(sObj);
	oObj2 = document.getElementById(sObj2);
	if (oObj && oObj2){
		iPlace = oObj2.scrollTop/(oObj2.scrollHeight-oObj2.offsetHeight);
		oObj.style.top = Math.floor(20+((oObj.parentNode.offsetHeight-62)*(iPlace)))+"px";
	}
}


function myParentOffsetTop(oParentNode){
   if (oParentNode != null && oParentNode.offsetTop) {
			if (oParentNode.parentNode) {
				return(oParentNode.offsetTop + myParentOffsetTop(oParentNode.parentNode));
			} else {
				return(oParentNode.offsetTop);
			}
	 } else {
	    return(0);
	 }
}

// use the scrollbar to control the flow
function vertScroll(oThis,oEvent,sBox){
	var oBox = document.getElementById(sBox);
	var parentOffsetTop = myParentOffsetTop(oThis.parentNode)+45;

	if (iScrolling == 2){
		if (!oEvent) { // sets the event for IE and removes a dimension from the parentnode function
			oEvent = window.event;
			parentOffsetTop = myParentOffsetTop(oThis.parentNode.parentNode)+148;
		}

		var iMoveTo = oEvent.clientY-(oThis.offsetHeight/2)-parentOffsetTop;
		var iMaxMove = oThis.parentNode.clientHeight-oThis.offsetHeight-20;
		var iPlace = Math.floor(((iMoveTo-20)/(iMaxMove-20))*100);


		if (iMoveTo < 20){
			oThis.style.top = 20 + "px";
		}	else if ((iMoveTo+oThis.offsetHeight+20) > oThis.parentNode.clientHeight){
			oThis.style.top = (oThis.parentNode.clientHeight-oThis.offsetHeight-20) + "px";
		} else {
			oThis.style.top = iMoveTo + "px";
			oBox.scrollTop = ((oBox.scrollHeight-oBox.offsetHeight)/100)*iPlace
		}
	}
}

// changing between main menus
function menuChange(iTo,oTab1,oTab2){
	oMain = document.getElementById("mainMenu");
	oMy = document.getElementById("myPages");
	if (iTo == 2 && oMain && oMy){
		oMain.style.display = "none";
		oMy.style.display = "block";
		oTab1.style.backgroundImage = "url(/images/backgrounds/bg_menuheader1.gif)";
		oTab2.style.backgroundImage = "url(/images/backgrounds/bg_menuheader2_active.gif)";
		oTab1.style.color = "#f2f1f1";
		oTab2.style.color = "#1b357a";

	} else if (oMain && oMy){
	oMy.style.display = "none";
		oMain.style.display = "block";
		oTab1.style.groundImage = "url(/images/backgrounds/bg_menuheader1_active.gif)";
		oTab2.style.backgroundImage = "url(/images/backgrounds/bg_menuheader2.gif)";
		oTab1.style.color = "#1b357a";
		oTab2.style.color = "#f2f1f1";
	}
}

// set actions to the main menu tabs
function setMenuAction(status){
	var oBox = document.getElementById("menuBox");
	if (!oBox) oBox = document.getElementById("menuBoxMy");

	var oTab1 = oBox.getElementsByTagName("li")[0];
	var oTab2 = oBox.getElementsByTagName("li")[1];

	if(status==1) {
		if (oTab1 && oTab2){
			oTab1.onclick = function (){
				document.location = '/334';
				//menuChange(1,oTab1,oTab2);
			}
			oTab2.onclick = function (){
				document.location = '/807';
				//menuChange(2,oTab1,oTab2);
			}
		}
	}else if(status==2) {
		if (oTab1 && oTab2){
			oTab1.onclick = function (){
				document.location = '/334';
				//menuChange(1,oTab1,oTab2);
			}
			oTab2.onclick = function (){
				document.location = '/1912';
				//menuChange(2,oTab1,oTab2);
			}
		}
	} else {
		oTab2.onclick = function(){
			document.location = '/807';

		};
	}
}

// messure the total height and give menubox a similar height, so it fills the total height of the site
function correctMenuSize(){
	var oMenuBox = document.getElementById("menuBox");
	if (!oMenuBox) oMenuBox = document.getElementById("menuBoxMy");
	
	if (!oMenuBox) return;

	var totalHeight = oMenuBox.parentNode.offsetHeight;
	var menuBoxes = oMenuBox.childNodes;
	var collectedHeight = 0;
	var menuInner;
	for (var i=0;i<menuBoxes.length;i++){ // go through all childs in the menuBox
		if (String(menuBoxes[i]).indexOf("Text") == -1){ // avoid reading text objects
			collectedHeight = collectedHeight + menuBoxes[i].offsetHeight; // count the height of all the elements

			if (menuBoxes[i].className == "menuBody"){ // find the menuBodyInner object
				if (String(menuBoxes[i].childNodes[0]).indexOf("Text") == -1){ // avoid reading text objects
					menuInner = menuBoxes[i].childNodes[0];
				} else {
					menuInner = menuBoxes[i].childNodes[1];
				}
			}
		}
	}
	collectedHeight += 26; // add the height of missing margins and border sizes

 if (collectedHeight < totalHeight){ // check if there is a need for changing the height of the menu
 		var menuInnerDiff = collectedHeight - menuInner.offsetHeight;
		menuInner.style.height = (totalHeight-menuInnerDiff) + "px";
	}
}

function checkSearchBoxText(){
	if(document.getElementById('leftmenusearchbox').value  == "Indtast søgeord") {
		document.getElementById('leftmenusearchbox').value = "";
	}
}

function setPopup(oThis, sHeight, sWidth){
	var popupWin = window.open(oThis.href, "popWin", "width=" + sWidth + ", height=" + sHeight + ", status=0, resizable=0, scrollbars=1");
	return false;
}

function showWebTv(qs){
	if(qs){
		href = "/webtv"+qs;
	} else {
		href = "/webtv";
	}
	sHeight = 780;
	sWidth = 750;
	scrollbars = "no";
	if(screen.height < sHeight) {
		sHeight = screen.height;	
		scrollbars = "yes";
	}
	var popupWin = window.open(href, "tv_player", "width=" + sWidth + ", height=" + sHeight + ", status=0, resizable=1, scrollbars=" + scrollbars);
	return false;
}

var ajax_targetid = "";
var ajax_modid = "";
var ajax_xmlhttp_content = null;
var ajax_statusid = "";
var ajax_statusidx = 0;
var ajax_statusupdaterTimer = null;
var ajax_statustext = "Henter indhold";

function ajax_loadContent(targetid, modid, qs, statusid, statustext) {
	ajax_targetid = targetid;
	ajax_modid = modid;
	ajax_statusid = statusid;
	ajax_statusidx = 0;

	if (qs && qs != "") qs = "&" + qs;
	if (statustext) ajax_statustext = statustext;

	ajax_statusUpdater();

	var oDate = new Date();
	ajax_xmlhttp_content = getXmlhttp('text/xml');
	ajax_xmlhttp_content.onreadystatechange = ajax_contentUpdate;
	ajax_xmlhttp_content.open('GET', "/services/ajax_update.php?modid=" + modid + qs + "&ts="+oDate.getTime(),true);
	ajax_xmlhttp_content.send(null);

}

function ajax_statusUpdater() {
	if (ajax_statusid != "") {
		var oStatus = document.getElementById(ajax_statusid);
		if (oStatus) {
			ajax_statusidx++;
			if (ajax_statusidx > 4) ajax_statusidx = 0;
			txtDot = "";
			for (i = 1; i < ajax_statusidx; i++) {txtDot += "."; }
			oStatus.innerHTML = ajax_statustext + txtDot;
		}
		ajax_statusupdaterTimer = setTimeout(ajax_statusUpdater, 200);
	}
}

function ajax_contentUpdate(){

	if (ajax_xmlhttp_content.readyState == 4 && ajax_xmlhttp_content.status == 200) {
		ajax_parseUpdate();
	}
}

function ajax_parseUpdate() {
	var status = ajax_xmlhttp_content.responseXML.getElementsByTagName('status')[0].firstChild.data;

	if (status == 'ok') {
		// get the targetid
		var targetContainer = document.getElementById(ajax_targetid);

		if (targetContainer) {
			 if (ajax_xmlhttp_content.responseXML.getElementsByTagName("content")[0]) {
				 data = ajax_xmlhttp_content.responseXML.getElementsByTagName("content")[0].firstChild.data;
				 if(data.length > 0) {
				 	targetContainer.innerHTML = data;
				 }
			 }
		}
	}
	ajax_xmlhttp_content = null;

	if (ajax_statusid != "") {
		ajax_statusid = "";
		var oStatus = document.getElementById(ajax_statusid);
		if (oStatus) oStatus.innerHTML = "";
	}
}

function ajax_getXmlhttp(typeoverride) {

	var xmlhttp = null;

	if (window.XMLHttpRequest) {
	  xmlhttp = new XMLHttpRequest();
	  if ( typeof xmlhttp.overrideMimeType != 'undefined') {
	    xmlhttp.overrideMimeType(typeoverride);
	  }
	} else if (window.ActiveXObject) {
	  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	  xmlhttp = false;
	}

	return xmlhttp;
}

function writeFlashWebplayerLarge(loopid,longid,clipid,articletext,hostname) {
	var ts = (new Date()).getTime();

	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="410" height="339" id="borsen_player" align="middle">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="movie" value="http://borsenflash.jay.net/borsen_flash/_forside_player.swf?forcecache='+ts+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#ffffff" />');
	document.write('<param name="flashvars" value="loopid='+loopid+'&longid='+longid+'&clipid='+clipid+'&articletext='+articletext+'&hostname='+hostname+'" />');
	document.write('<embed src="http://borsenflash.jay.net/borsen_flash/_forside_player.swf?forcecache='+ts+'" flashvars="loopid='+loopid+'&longid='+longid+'&clipid='+clipid+'&articletext='+articletext+'&hostname='+hostname+'" quality="high" bgcolor="#ffffff" width="410" height="339" name="borsen_player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function writeFlashWebplayerSmall(loopid,longid,clipid,articletext,hostname) {
	var ts = (new Date()).getTime();

	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="287" height="247" id="borsen_player" align="middle">');
	document.write('<param name="allowScriptAccess" value="always" />');
	document.write('<param name="movie" value="http://borsenflash.jay.net/borsen_flash/_forside_player_small.swf?forcecache='+ts+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#ffffff" />');
	document.write('<param name="flashvars" value="loopid='+loopid+'&longid='+longid+'&clipid='+clipid+'&articletext='+articletext+'&hostname='+hostname+'" />');
	document.write('<embed src="http://borsenflash.jay.net/borsen_flash/_forside_player_small.swf?forcecache='+ts+'" flashvars="loopid='+loopid+'&longid='+longid+'&clipid='+clipid+'&articletext='+articletext+'&hostname='+hostname+'" quality="high" bgcolor="#ffffff" width="287" height="247" name="borsen_player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

/* TVBoks functions */
function tvBoxWebLI(oThis){
	if (oThis.className.indexOf(" over") > -1){
		oThis.className = oThis.className.substr(0,oThis.className.indexOf(" over"));
	}
	else {
		oThis.className = oThis.className + ' over';
		oThis.style.cursor = "pointer";
	}
}

/* CountDown functions */
var countdown_seconds_to_wait = 15;
var countdownTo;

function countdown_initCountdown(to, from) {

	var serverTo = 0;
	var serverFrom = 0;
	var now = new Date();
	var clientTimeStart = Math.floor(now.getTime()/1000);

	// db timestamp
	serverTo = parseInt(to);
	// server timestamp
	serverFrom = parseInt(from);

	// calculate new client end time
	countdownSecs = serverTo - serverFrom;
	countdownTo = clientTimeStart + countdownSecs;

	countdown_displayCountdown();
}

function countdown_displayCountdown() {

	var now = new Date();
	var clientTimeCurrent = Math.floor(now.getTime()/1000);

	var diffTimeSecs = countdownTo - clientTimeCurrent;
	var diffTimeMin = Math.floor(diffTimeSecs/60);

	var oSpan = document.getElementById("tvbox_countdown");
	if (oSpan) {
		var minToWrite = diffTimeMin;
		if (diffTimeMin < 1) minToWrite = "&lt;1";
		oSpan.innerHTML = minToWrite + " min.";
	}

	setTimeout("countdown_displayCountdown()", countdown_seconds_to_wait * 1000);

}



function bbntab_over(obj,image){

		//obj.style.zIndex='100';
		if(navigator.userAgent.indexOf('MSIE 6')!=-1){
			obj.style.background='none';
		}else{
			obj.style.background='url('+image+') no-repeat';
		}
		obj.style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+image+'\',sizingMethod=\'image\')';

}


function bbntab_out(obj,image,zindex){

		obj.style.zIndex=zindex;
		if(navigator.userAgent.indexOf('MSIE 6')!=-1){
			obj.style.background='none';
		}else{
			obj.style.background='url('+image+') no-repeat';
		}
		obj.style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+image+'\',sizingMethod=\'image\')';
			
}

// Flash TV - Afspil punktet i argumentslisten
function flashTvIsPlayingThis(iItem){
	var oBox = document.getElementById("flashTvPlayer")
	
	if (oBox){

		// start: dummy - indsæt video til flash afspiller
		var oPlayerObject = oBox.getElementsByTagName("object")[0];
		var oPlayerEmbed = oBox.getElementsByTagName("embed")[0];
		// end: dummy

		
		// skift playlist aktivering
		var aPlaylist = oBox.getElementsByTagName("li");
		
		for (var i=0;i<aPlaylist.length;i++){
			// fjern class fra punktet hvis det er sat og den ikke spiller mere
			if (aPlaylist[i].className == "playing" && i != iItem) aPlaylist[i].className = "";
			
			// sæt class på punktet hvis den spiller og den ikke har class sat
			if (aPlaylist[i].className != "playing" && i == iItem) aPlaylist[i].className = "playing";
		}
	}	
}

function flashplayer_ChangeBlock(blockid) {	
}

// Flash TV - sæt events på playlist punkter
function flashTvPlaylistEvents(){
	var oBox = document.getElementById("flashTvPlayer")
	
	if (oBox){
		var aPlaylist = oBox.getElementsByTagName("li");
		var oImg;
		var oDiv;
		// kør gennem alle punkterne og sæt hver deres onclick event på både img og div tag
		for (var i=0;i<aPlaylist.length;i++){
			aPlaylist[i].setAttribute("movieid",i);

			if (flashplayer_ChangeBlock) {				
				oImg = aPlaylist[i].getElementsByTagName("img")[0];
				oImg.onclick = function(){ flashplayer_ChangeBlock(this.parentNode.getAttribute("movieid")); }
	
				oDiv = aPlaylist[i].getElementsByTagName("div")[0];
				oDiv.onclick = function(){ flashplayer_ChangeBlock(this.parentNode.getAttribute("movieid")); }
			}			
		}
	}	
}


/* change the window in the back to the links url */
function changeBackWindow(oThis){

	if (window.opener != null){
		this.blur();
		window.opener.location = oThis.href;
	} else {
		this.blur();
		window.open(oThis.href);
	}
}

function tabbedListChange(day,id) {
	var day;
	var id;
	var days = new Array(1,7,30);
	
	for (i = 0; i < days.length; i++) {	
		if($('content' + id + '_' + days[i]) != null) {
			$('menu'+ id + '_' + days[i]).className = '';
			$('content'+ id + '_' + days[i]).style.display = 'none';		
		}
	}
	
	$('menu'+ id + '_' + day).blur();
	$('menu'+ id + '_' + day).className = 'active';
	$('content'+ id + '_' + day).style.display = 'block';
	
	return false;
}

// jQuery plugin to switch wether or not a checkbox is checked
if (typeof jQuery != 'undefined')  {
	jQuery.fn.check = function(mode) {
		// if mode is undefined, use 'on' as default
		var mode = mode || 'on';
		return this.each(function() {
			switch(mode) {
				case 'on':
					this.checked = true;
					break;
				case 'off':
					this.checked = false;
					break;
				case 'toggle':
					this.checked = !this.checked;
					break;
			}
		});
	};

}


function printBrowserName() {
	
	browserName = 'Ukendt';
	
	thisUserAgent = navigator.userAgent;

	if (thisUserAgent.indexOf('Firefox/2') > 1) {
		browserName = 'Firefox 2';
	} 

	if (thisUserAgent.indexOf('Safari') > 1) {
		browserName = 'Safari';
	} 

	
	if (thisUserAgent.indexOf('MSIE 6') > 1) {
		browserName = 'Internet Explorer 6';
	} 
	
	if (thisUserAgent.indexOf('MSIE 7') > 1) {
		browserName = 'Internet Explorer 7';
	} 
	
	
	document.write(browserName);
//	document.write(navigator.appVersion);

		
}
function printOSName() {
	
	OSName = 'Ukendt';
	
	thisUserAgent = navigator.userAgent;

	if (thisUserAgent.indexOf('Windows NT 5.1') > 1) {
		OSName = 'Windows XP';
	} 

	if (thisUserAgent.indexOf('Windows NT 6.0') > 1) {
		OSName = 'Windows Vista';
	} 

	if (thisUserAgent.indexOf('Mac OS X') > 1) {
		OSName = 'Mac OS X';
	} 

	document.write(OSName);
}

function printRes() {
	width = screen.width;
	height = screen.height;
	document.write(width + 'x' + height);

}
function generateClicks() {
	jQuery(".a25_quickpoll_list ul li a").unbind('click').click(function() {
		
			var ul = jQuery(this).parent().parent();
			//ul.siblings('.pollListActive').removeClass('pollListActive');
			//ul.siblings('.pollListResult').hide();
			pollResultShow(ul.attr('id').replace('pollListId',''), ul);
			return false;
	});
}

function pollShowContent(divID,modID,offset,pageNum) {
	jQuery.post("/services/ajax/a25_list_content.php", { modID: modID, offset: offset, pageNum:pageNum }, function(data) {
		var obj = document.getElementById(divID);
		obj.innerHTML=data;
		generateClicks();
  	});
}

function pollResultShow(polldId, ul) {
	
	jQuery.post("/services/ajax/a25_list.php", { pollResultid: polldId }, function(data) {
		var content = ul.parent('.content');
		content.toggleClass('opened');
		ul.toggleClass('pollActive').next().html(data).toggleClass('pollListActive');
		  content.parents('.a25_quickpoll_list:first').find('div.opened').not(content).removeClass('opened').find('.pollActive').removeClass('pollActive').next().removeClass('pollListActive');
  	});
}

function pollVote(pollId, answerId, dl) {
	jQuery.post("/services/ajax/a25_show.php", { pollId: pollId, answerId: answerId}, function(data) {
		dl.html(data).next().remove().end().parent().next('.formerPolls').remove().end().parent().parent().addClass('a25_quickpoll_ajax');
	});
}



// fills out subscription address with preset address details
function useAsNewAddress(country,postal,city,street,houseno,houseletter,floor,side,address2,postalbox,postalboxno){
	jQuery('#subCountry').val(country);
	jQuery('#subPostalCode').val(postal);
	jQuery('#subCity').val(city);
	jQuery('#subStreet').val(street);
	jQuery('#subHouseNumber').val(houseno);
	jQuery('#subHouseLetter').val(houseletter);
	jQuery('#subFloor').val(floor);
	jQuery('#subAppartmentNumberSide').val(side);
	jQuery('#subAddress2').val(address2);
	jQuery('#subBox').val(postalbox);
	jQuery('#subBoxPostalCode').val(postalboxno);
}
// --------------- t21 live player code start ----------------
function t21_live_player_version_check(){
	var requiredPlayerVersionMajor = 9;
	var requiredPlayerVersionMinor = 0;
	var requiredPlayerVersionRelease = 115;
	var playerVersion = swfobject.getFlashPlayerVersion();
	//check now
	if (playerVersion.major >= requiredPlayerVersionMajor){
		//all is ok
		if (playerVersion.major == requiredPlayerVersionMajor){
			//we have the same major version => check minor too
			if (playerVersion.minor >= requiredPlayerVersionMinor){
				if (playerVersion.minor == requiredPlayerVersionMinor){
					//we have the same major version => check release too
					if (playerVersion.release >= requiredPlayerVersionRelease){
						//load swf
						return 1;
					}
				} else {
					return 1;
				}
			}
		} else {
			return 1;
		}
	}
	return -1;
}
var xmlHttpLive;
function t21_live_player_first_time(variable, root_url, bcu, acu, videoplazza, vpid, flashOk, frames_active, Topframe1, Topframe2, Leftframe1, Leftframe2, Rightframe1, Rightframe2, Bottomframe1, Bottomframe2, nwindow){
	var a = variable;
	var l_array=a.split("*");
	if (l_array[0] == 2){
		var docum = document.getElementById("player_parent");
		docum.style.display = 'block';
		if (flashOK == 1){
			if (l_array[4] == 'undefined'){
				l_array[4] = '';
			}
			var flashvars = {};
			flashvars.filename = root_url+'/services/ajax/ajax_livetv_xml.php?url='+l_array[1]+'%26live='+l_array[2]+'%26offset='+l_array[3]+'%26title='+l_array[4]+'%26bcu='+bcu+'%26acu='+acu+'%26videoplazza='+videoplazza+'%26vpid='+vpid+'%26frames_active='+frames_active+'%26Topframe1='+Topframe1+'%26Topframe2='+Topframe2+'%26Leftframe1='+Leftframe1+'%26Leftframe2='+Leftframe2+'%26Rightframe1='+Rightframe1+'%26Rightframe2='+Rightframe2+'%26Bottomframe1='+Bottomframe1+'%26Bottomframe2='+Bottomframe2+'%26new='+nwindow+'';
			var params = {};
			params.quality = "best";
			params.wmode = "window";
			params.allowfullscreen = "true";
			params.allowscriptaccess = "always";
			params.bgcolor = "#f7e7da";
			var attributes = {};
			attributes.id = "video_live";
			var Pwidth = '';
			if (frames_active == 1){
				Pwidth = '295.9';
			}else{
				Pwidth = '265.9';
			}
			swfobject.embedSWF("/flash/player/borsentv/videoplayer_live.swf", "live_player", "368", Pwidth, "9.0.115", "expressInstall.swf", flashvars, params, attributes);
		}
	}
}
function t21_live_player_showajax(file, root_url, bcu, acu, videoplazza, vpid, flashOk, frames_active, Topframe1, Topframe2, Leftframe1, Leftframe2, Rightframe1, Rightframe2, Bottomframe1, Bottomframe2, nwindow, withContent){
	xmlHttpLive = t21_live_player_GetXmlHttpObject();
	if (xmlHttpLive==null){
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url = file;
	xmlHttpLive.onreadystatechange = function(){
		if (xmlHttpLive.readyState==4 || xmlHttpLive.readyState=="complete"){
			var a = xmlHttpLive.responseText;
			var l_array = Array();
			l_array=a.split("*");
			// start play
			if (l_array[0] == 1){
				document.getElementById("player_parent").style.display = 'block';
				if (flashOK == 1){
					if (l_array[4] == 'undefined'){
						l_array[4] = '';
					}
					document.getElementById("player_parent").innerHTML = '<div class="modulesmallspacerdots21"></div><div id="live_player"></div>';
					//document.getElementById("player_parent").style.display = 'block';
					var flashvars = {};
					flashvars.filename = root_url+'/services/ajax/ajax_livetv_xml.php?url='+l_array[1]+'%26live='+l_array[2]+'%26offset='+l_array[3]+'%26title='+l_array[4]+'%26bcu='+bcu+'%26acu='+acu+'%26videoplazza='+videoplazza+'%26vpid='+vpid+'%26frames_active='+frames_active+'%26Topframe1='+Topframe1+'%26Topframe2='+Topframe2+'%26Leftframe1='+Leftframe1+'%26Leftframe2='+Leftframe2+'%26Rightframe1='+Rightframe1+'%26Rightframe2='+Rightframe2+'%26Bottomframe1='+Bottomframe1+'%26Bottomframe2='+Bottomframe2+'%26new='+nwindow+'';
					var params = {};
					params.quality = "best";
					params.wmode = "window";
					params.allowfullscreen = "true";
					params.allowscriptaccess = "always";
					params.bgcolor = "#f7e7da";
					var attributes = {};
					attributes.id = "video_live";
					var Pwidth = '';
					if (frames_active == 1){
						Pwidth = '295.9';
					}else{
						Pwidth = '265.9';
					}
					swfobject.embedSWF("/flash/player/borsentv/videoplayer_live.swf", "live_player", "368", Pwidth, "9.0.115", "expressInstall.swf", flashvars, params, attributes);
				}
			}
			// stop play / hide
			if (l_array[0] == 3){
				if (withContent){
					document.getElementById("player_parent").style.display = 'none';
					document.getElementById("additionalTextPlayer").style.display = 'block';
				}else{
					document.getElementById("player_parent").innerHTML = '<div class="modulesmallspacerdots21"></div><div id="live_player"></div>';
					document.getElementById("player_parent").style.display = 'none';
				}
			}
			// continue play
			if (l_array[0] == 2){}
		}
	};
	xmlHttpLive.open("GET",url,true);
	xmlHttpLive.send(null);
}
function t21_live_player_GetXmlHttpObject(){
	var xmlHttpLive=null;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttpLive=new XMLHttpRequest();
	}
	catch (e){
		// Internet Explorer
		try{
			xmlHttpLive=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttpLive=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttpLive;
}
// --------------- t21 live player code end ----------------
// ---------------- xx_elektronik_avis_forsider -------------
/** Function that displays the Thumb for magasines
 * 
 * @name _xx_drawThumb
 * @param id - zmag id
 * @param width - thumb's width
 * @param height - thumb's height
 * @param pageid - zmag's page
 * @param url - zmag's url
 * - functionality: we are displaying the thumb on C18 Super Module, xx_elektronik_avis_forsider
 */
function _xx_drawThumb(id, width, height, pageId, url){
	var id = new Thumb(id, 'clientThumb'+id);
	id.setSize(width, height);
	id.setPageID(pageId);
	id.setLaunchURL(url);
	id.setFullscreen(false);
	id.draw();
}
/** Function that displays the Tiny Magasin for magasines
 * 
 * @name _xx_drawTinyCatalog
 * @param id - zmag id
 * @param date - zmag's date
 * @param color - zmag's background color
 * @param width - thumb's width
 * @param height - thumb's height
 * @param page - zmag's page
 * @param url - zmag's url
 * - functionality: we are displaying the tiny magasine on C18 Super Module
 */
function _xx_drawTinyCatalog(id, date, color, width, height, page, url){
	var mag = new TinyCatalog(id, date);
	mag.setBackgroundColor(color);
	mag.setSize(width, height);
	mag.setPages(page);
	mag.setLaunchURL(url);
	mag.setTarget("_blank"); 
	mag.draw();
}
/** Function that initializes the ul position for newsticker and calculetes the scrolling speed on A26 Newsticker module
 * 
 * @name slider_init
 * @param time - time to scroll news 
 */
function slider_init(time){
	if (time > 10){ time = 10; }
	var width=0;		
	var currentPosition=0;
	jQuery("#mySlide ul li").each(function(){			
		width= jQuery(this).width();
		jQuery(this).css({width : width+"px", left : currentPosition+"px"});
		currentPosition += jQuery(this).width();			
	});		
	jQuery("#mySlide ul").css({"left" : jQuery("#mySlide").width()+"px", "width" : currentPosition});	
	speed=(jQuery('#mySlide').width()+jQuery("#mySlide ul").width())*140/time;
}
/** Functions that creates the animation on A26 Newsticker module
 * 
 * @name slider
 */
function slider(){		
	jQuery("#mySlide ul").css({"visibility" : "visible"}).animate({"left" : "-"+jQuery("#mySlide ul").width()+"px"}, speed, "linear", function(){
		jQuery("#mySlide ul").css({"left" : jQuery("#mySlide").width()+"px"});			
		slider();
	});				
}

// --------------- H3 Userinfo code start ----------------
/**
 *  @name function getResolution()
 *	@param -
 *	@return string - an string with the current screen resolution	 
 */
function getResolution(){			
	intWidth = (screen.width) ? screen.width : "";
	intHeight = (screen.height) ? screen.height : "";
	// check for windows off standard dpi screen res
	if (typeof(screen.deviceXDPI) == "number") {
		intWidth *= screen.deviceXDPI/screen.logicalXDPI;
		intHeight *= screen.deviceYDPI/screen.logicalYDPI;
	} 
	
	strResolution = intWidth + " x " +	intHeight;
	if (intWidth && intHeight) { 
		return strResolution;
	}			
	return "";	
}

/**
 *  @name function getFlashVersion()
 *	@param -
 *	@return string - an string with the current Flash version	 
 */
function getFlashVersion(){ 
	// ie 
	try { 
		try { 
			// avoid fp6 minor version lookup issues 
			objActiveX = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
			try { 
				objActiveX.AllowScriptAccess = 'always'; 
			} 
			catch(e) { 
				return '6,0,0'; 
			} 
		} 
		catch(e) {
		} 
		
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
	// other browsers 
	} catch(e) { 
		try { 
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
				return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
			} 
		} catch(e) {} 
	} 
	
	return '0,0,0'; 
} 

/**
 *  @name function displayFlashVersion()
 *	@param -
 *	@return string - an string with the current Flash version, with "," replaced by "."
 */
function displayFlashVersion(){
	strVersion = getFlashVersion();
	for(intI=0; intI<strVersion.length; intI++){
		if(strVersion.charAt(intI) == ","){
			strVersion = strVersion.replace(",", ".");
		}	
	}
	return strVersion;
}

/**
 *  @name function checkAdobeInstalled()
 *	@param -
 *	@return boolean - an boolean value
 * 	- functionality: we are checking if Acrobat Reader is installed
 */
function checkAdobeInstalled(){ 				
	if (navigator.plugins && navigator.plugins.length) {//other browsers check
		for (intI = 0; intI < navigator.plugins.length; intI++ ) {			
			if (navigator.plugins[intI].name.indexOf('Adobe Acrobat') != -1) {				
				return true;					
			}
		}
	} else if (window.ActiveXObject){//ie check
		for (intI = 2; intI < 10; intI++) {
			try	{
				oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+intI+"');");
				if (oAcro) {
					return true;						
				}
			}
			catch(e) {}
		}

		try	{
			oAcro4=new ActiveXObject('PDF.PdfCtrl.1');
			if (oAcro4)	{
				return true;				
			}
		}
		catch(e) {}

		try {
			oAcro7=new ActiveXObject('AcroPDF.PDF.1');
			if (oAcro7)	{
				return true;					
			}
		}
		catch(e) {}
	}
	return false;		
}

/**
 *  @name function getInfo()
 *	@param -
 *	@return -
 * 	- functionality: we are displaying on DOM elements, the values from the functions above (screen resolution, flash version, Acrobat Reader status)
 */
function getInfo(){
	strResolution = getResolution();
	jQuery("#resolution_info").append(strResolution);
	jQuery("#resolution_form").val(strResolution);
	
	strFlashVersion = displayFlashVersion();
	jQuery("#flash_info").append(strFlashVersion);	
	jQuery("#flash_form").val(strFlashVersion);	
	
	if(checkAdobeInstalled()){
		jQuery("#adobe_info").append("Installeret");
		jQuery("#adobe_form").val("Installeret");
	} else {
		jQuery("#adobe_info").append("Ikke installeret");
		jQuery("#adobe_form").val("Ikke installeret");
	}
}
// --------------- H3 Userinfo code end ----------------
// --------------- H3 Userinfo code end ----------------
/**
 *  @name function getQuery()
 *	@param -
 *	@return -
 * 	- functionality: module_m2_soegefelt.class.inc, we populate an input value depending on choosed values from a dropdownlist
 */
function getQuery(){
	var intType = jQuery("#intType").val();
	var strQuery = jQuery("#query").val();
	var strQuery = strQuery.replace(/<(.|\n)*?>/g, "");
	var query = jQuery.trim(strQuery);
	query = query.replace(/(\')/g, "");
	query = query.replace(/(\")/g, "");
	query = query.replace(/(\\)/g, "");
	query = query.replace(/(\>)/g, "");
	query = query.replace(/(\<)/g, "");
	query = query.replace(/(\/)/g, "");
	query = query.replace(/(\\0)/g, "");
	query = query.replace(/(\ OR )/g, " ");
	if(query.match(/(\+)/)){
		query = query.replace(/(\+)/g, "");
	}
	switch(intType){
		case '1':
			q = query;
			break;
		case '2':
			if(query.substr(0,1) != '+'){
				q = "+" + query;
			}
			q = q.replace(/(\ )/g, " +");
			break;
		case '3':
			q = query.replace(/(\ )/g, " OR ");
			break;
		case '4':
			q = '"' + query + '"';
			break;
	}
	if(q){
		jQuery("#query").attr('value', q);
	}
}