// Content: js global
var navFrame, fbFrame;
var arDestinations = new Array();

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : 
    oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function initHome() {
	checkBrowser();
	top.mainContainer = document.getElementById('maincontainer');
	updateSize();
	if (document.getElementById('language_selector')) ls = new LanguageSelector();
	FBfill(true);
	setTriggersHome();
	setOtherKLMSites();
	webSensor();
	loadNav();
}
function initLocalHome() {
	setTriggersHome();
	setOtherKLMSites();
	webSensor();
	loadNav();
}
function init() {
	checkBrowser();
	top.mainContainer = document.getElementById('maincontainer');
	if (document.getElementById('language_selector')) ls = new LanguageSelector();
	FBfill();
	BBfill(false);
	updateSize();
	setTriggers();
	setOtherKLMSites();
	webSensor();
	loadNav();
	preloadImages();
	var divbuttonleft = document.getElementById("appleft");
	if (divbuttonleft) {
		divbuttonleft.style.width = 1 +"px";
	}
	var divbuttonright = document.getElementById("appright");
	if (divbuttonright) {
		divbuttonright.style.width = 1 +"px";
	}
}
function webSensor() {
	var cook=document.cookie;
	var i=cook.indexOf('KLMCOM_SESSIONCOOKIE');
	var strResolutie=window.screen.width+"x"+window.screen.height;
	if(i<0)
	{
		var id1=parseInt(Math.random()*2147418112);		
		document.cookie='KLMCOM_SESSIONCOOKIE='+id1+new Date().getTime()+'--'+strResolutie+';path=/;domain=.klm.com'
	}	
	
	
	strCDom=document.location.host.substring(document.location.host.lastIndexOf('.',document.location.host.lastIndexOf('.') - 1));
	keepdays=180;
	
	cook=document.cookie;
	i=cook.indexOf('MfTrack_js');
	if(i<0){
	        // the cookie was not yet present, create a new cookie
	        id1=parseInt(Math.random()*2147418112);
	        strCVal=id1+'.'+new Date().getTime()+'--'+strResolutie;
	        document.cookie='MfTrack_js='+strCVal+'; path=/; domain='+strCDom;
	}
	strPVal='';
	i=cook.indexOf('MfPers_js=');
	if(i<0){
	        // the cookie was not yet present, create a new cookie
	        id1=parseInt(Math.random()*2147418112);
	        strPVal=id1+'.'+new Date().getTime()+'--'+strResolutie;
	}
 	else {
	        // change expire date of persistent cookie, with same value
	        j=cook.indexOf(";",i+10);
	        if (j<0)
	                strPVal=cook.substring(i+10);
	        else
	                strPVal=cook.substring(i+10, j);
	       // Temperaly check if cookie is oke, keep test till 1-1-2009
	       re = /^\d+\.\d+(\-){2}\d+x\d+$/
	       // cookie not oke, create new value
	       if (!re.test(strPVal))
	       {
	                id1=parseInt(Math.random()*2147418112);
	                 strPVal=id1+'.'+new Date().getTime()+'--'+strResolutie;
	       }  
	}
	expires=new Date();
	expires.setTime(expires.getTime()+(keepdays*24*60*60*1000));
	document.cookie='MfPers_js='+strPVal+'; path=/; domain='+strCDom+'; expires='+expires.toGMTString();
	
	var qs = window.location.search
	var adcamp = getParameter(qs, "adcamp")
	if (adcamp)
	{
		expires=new Date();
		expires.setTime(expires.getTime()+(30*24*60*60*1000));
		var content = "&adcamp=" + adcamp + "&adchan=" + getParameter(qs, "adchan") + "&adtype=" +
			getParameter(qs, "adtype") + "&adctry=" + getParameter(qs, "adctry") + "&adlang=" +
			getParameter(qs, "adlang") + "&http_referrer=" + document.referrer;
		document.cookie="SADCAMP=" + content + "; path=/; domain=" + strCDom;
		document.cookie="PADCAMP=" + content + "; path=/; domain=" + strCDom + "; expires="+expires.toGMTString();
	}
}
function FBfill (home) {
	if (document.getElementById('jffp_login')) {
		fbFrame = new RPCFrame(window);
		if (home)
			fbFrame.setLocation('/travel/dk_en/jffp.htm?loadProfile=true&date=' + new Date(), FBfillItHome, 'GET')
		else
			fbFrame.setLocation('/travel/dk_en/jffp.htm?loadProfile=true&date=' + new Date(), FBfillIt, 'GET')
	}
}

function FBfillIt () {
  if (!fbFrame.getHTMLById('content')){
               var seealsoblocknewtop= document.getElementById('seealsoblocknewtop');
               var contentblock = document.getElementById('contentblock');
               var seealsobot= document.getElementById('seealsobot');
               if (!seealsoblocknewtop) {
                   if(contentblock && seealsobot) {
                      contentblock.style.background='white';
                      seealsobot.style.background='white';
                   }
               }
		return;
  }
	document.getElementById('jffp_login').innerHTML = fbFrame.getHTMLById('content').innerHTML;
	initFbbox();
	toggleMilesPlus();
	try {
		checkBB();
	} catch (e) {}
	var fbNumber = getCookie('fbNumber');
	if (fbNumber)
	{
		var elems = document.getElementsByName('miles');
		for (var i = 0; i < elems.length; i++)
		{
			elems[i].value = fbNumber;
		}
	}
}

function FBfillItHome () {
	document.getElementById('jffp_login').innerHTML = fbFrame.getHTMLById('content').innerHTML;
	initFbbox(true);
	var fbNumber = getCookie('fbNumber');
	if (fbNumber)
	{
		var elems = document.getElementsByName('miles');
		for (var i = 0; i < elems.length; i++)
		{
			elems[i].value = fbNumber;
		}
	}
}

function initFbbox(home)
{
	var dashboarddiv = document.getElementById('dashboard')
	var fbbox = getElementsByClassName(document,'div','fbbox');
	if(fbbox.length == 1)
	{
		var fbboxesBig = getElementsByClassName(fbbox[0],'div','fbboxbig');
		var fbboxesVisual = getElementsByClassName(fbbox[0],'img','fbbox-visual');
		var fbboxesInloggenLabel = getElementsByClassName(fbbox[0],'a','fbbox-inloggen-label');
		var fbboxesInloggen = getElementsByClassName(fbbox[0],'a','fbbox-inloggen');
		var fbboxesContentBg = getElementsByClassName(fbbox[0],'div','fbbox-content-bg');
		var fbboxesContent = getElementsByClassName(fbbox[0],'div','fbbox-content');
		var fbboxesOpacitylayer = getElementsByClassName(fbbox[0],'div','fbbox-opacitylayer');
		var fbboxesLoginlayer = getElementsByClassName(fbbox[0],'div','fbbox-loginlayer');
		var fbboxesLoginlayerMessage = getElementsByClassName(fbbox[0],'p','fbbox-loginlayer-message');
		var fbboxesSluit = getElementsByClassName(fbbox[0],'a','fbbox-sluit');
		var fbboxesPushin = getElementsByClassName(fbbox[0],'div','fbbox-pushin');
		var fbboxPromotion = document.getElementById('fbbox-promotion');
		var pagecontent = document.getElementById('content');
		var seealsoblock = document.getElementById('seealso');
		var seealsoblockspacetop= document.getElementById('seealsoblockspacetop');
		var seealsoblockpush= document.getElementById('seealsoblockpush');
		var seealsoDivBot = document.getElementById('seealsobot')

		if (!(seealsoDivBot)){
			var seealsoDivBot = getElementsByClassName(document,'div','largeseealsobot')
		}
				
		if (seealsoblockpush){
			var strSeeAlsoHeight=(seealsoblockpush.offsetHeight);
		}
		if (pagecontent){
			var strPagecontent=(pagecontent.offsetHeight);
		}else{
			var pagecontent = document.getElementById('contentblock4col');
			if (pagecontent){
				var strPagecontent=(pagecontent.offsetHeight);
				var bExtraIframe = true
			}
		}
		
		
		if (!(seealsoblock)){
			seealsoblock = document.getElementById('recent');
		}
		if ((seealsoblock) && (bExtraIframe)){
			var contentcontainer = document.getElementById('contentcontainer');
			contentcontainer.style.background=("transparent url(/travel/dk_en/images/content_y_tcm83-120640.gif) repeat-y scroll 0% 50%");
		}
		var fbboxesHeight = fbboxesContent[0].offsetHeight - 35;
		if (fbboxesBig.length == 0) {
			fbboxesHeight += 45;
		}
		if(fbboxesInloggen.length == 1 && fbboxesOpacitylayer.length == 1 && fbboxesLoginlayer.length == 1 && fbboxesSluit.length == 1) {
			addEventHandler(fbboxesInloggen[0],'click', function(e) {
				if (fbboxesLoginlayerMessage.length == 2 && fbboxPromotion) {
				if (!navigator.cookieEnabled) {
					fbboxesLoginlayerMessage[0].style.display = 'none';
					fbboxesLoginlayerMessage[1].style.display = 'block';
					fbboxPromotion.className = 'fbbox-warning';
				} else {
					fbboxesLoginlayerMessage[0].style.display = 'block';
					fbboxesLoginlayerMessage[1].style.display = 'none';
					fbboxPromotion.className = '';
				}
				}
				fbboxesOpacitylayer[0].style.display = 'block';
				fbboxesLoginlayer[0].style.display = 'block';
				fbboxesSluit[0].style.display = 'block';
				fbboxesInloggen[0].style.display = 'none';
			});
			addEventHandler(fbboxesSluit[0],'click', function(e) {
				fbboxesOpacitylayer[0].style.display = 'none';
				fbboxesLoginlayer[0].style.display = 'none';
				fbboxesSluit[0].style.display = 'none';
				fbboxesInloggen[0].style.display = 'block';										 
			});			
		}
		if(fbboxesInloggenLabel.length == 1 && fbboxesPushin.length == 1 && fbboxesContentBg.length == 1 && fbboxesContent.length == 1) {
			addEventHandler(fbboxesInloggenLabel[0],'click', function(e) {
				fbboxesPushin[0].className = 'fbbox-pushin';
				fbboxesContent[0].style.display = 'block';
				fbboxesContentBg[0].style.display = 'block';
				if(fbboxesVisual.length == 1){fbboxesVisual[0].style.display = 'block';}
				if(fbboxesInloggenLabel.length == 1){fbboxesInloggenLabel[0].style.display = 'none';}
				if(fbboxesInloggen.length == 1){fbboxesInloggen[0].style.display = 'none';}
				if(fbboxesOpacitylayer.length == 1){fbboxesOpacitylayer[0].style.display = 'block';}
				if(fbboxesLoginlayer.length == 1){fbboxesLoginlayer[0].style.display = 'block';}
				if(fbboxesSluit.length == 1){fbboxesSluit[0].style.display = 'block';}									 
			});
		}
		if(fbboxesPushin.length == 1 && fbboxesContentBg.length == 1 && fbboxesContent.length == 1) {
		    	addEventHandler(fbboxesPushin[0],'click', function(e) {
				if(fbboxesPushin[0].className == 'fbbox-pushin') {
					fbboxesPushin[0].className = 'fbbox-pushout';
					fbboxesContentBg[0].style.display = 'none';
					fbboxesContent[0].style.display = 'none';
					if(fbboxesVisual.length == 1){fbboxesVisual[0].style.display = 'none';}
					if(fbboxesInloggenLabel.length == 1){fbboxesInloggenLabel[0].style.display = 'block';}
					if(fbboxesInloggen.length == 1){fbboxesInloggen[0].style.display = 'none';}
					if(fbboxesOpacitylayer.length == 1){fbboxesOpacitylayer[0].style.display = 'none';}
					if(fbboxesLoginlayer.length == 1){fbboxesLoginlayer[0].style.display = 'none';}
					if(fbboxesSluit.length == 1){fbboxesSluit[0].style.display = 'none';}
					setCookie("mpopen", "false", 0);
					if (seealsoblock) seealsoblock.style.paddingTop = 0;
					if ((seealsoblockspacetop) && (dashboarddiv)){
						seealsoblockspacetop.style.height= 0 + "px";
					}
					if ((seealsoblockspacetop) && (!(dashboarddiv))){
						seealsoblockspacetop.style.height= 41 + "px";
					}
					if((strSeeAlsoHeight > 0) && (strPagecontent > 0) && (bExtraIframe)){
						pagecontent.style.minHeight=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, false) + 50 + "px";
						pagecontent.style.height=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, false) + 50 + "px";
					}				
					if((strSeeAlsoHeight > 0) && (strPagecontent > 0) && (!(bExtraIframe))){
						pagecontent.style.minHeight=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, false) + "px";
						pagecontent.style.height=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, false) + "px";
				}
				} else {
					fbboxesPushin[0].className = 'fbbox-pushin';
					fbboxesContentBg[0].style.display = 'block';
					fbboxesContent[0].style.display = 'block';
					if(fbboxesInloggenLabel.length == 1){fbboxesInloggenLabel[0].style.display = 'none';}
					if(fbboxesVisual.length == 1){fbboxesVisual[0].style.display = 'block';}
					if(fbboxesInloggen.length == 1){fbboxesInloggen[0].style.display = 'block';}
					setCookie("mpopen", "true", 0);

					if (seealsoblock) {
						seealsoblock.style.paddingTop = (fbboxesHeight-17) + "px";
					}
					if ((seealsoblockspacetop) && (dashboarddiv)){
						seealsoblockspacetop.style.height= 33+ "px";
					}
					if ((seealsoblockspacetop) && (!(dashboarddiv))){
						seealsoblockspacetop.style.height= 74 + 'px';
					}
					if((strSeeAlsoHeight > 0) && (strPagecontent > 0) && (bExtraIframe)){
						pagecontent.style.minHeight=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, true) + 50 + "px";
						pagecontent.style.height=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, true) + 50 + "px";
						if (!(seealsoDivBot)){
							var seealsoDivBot = document.createElement('div');
							seealsoDivBot.setAttribute('id','');
							seealsoDivBot.setAttribute('class','largeseealsobot');
							pagecontent.appendChild(seealsoDivBot);
						}
					}
					if((strSeeAlsoHeight > 0) && (strPagecontent > 0) && (!(bExtraIframe))){
						pagecontent.style.minHeight=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, true) + "px";
						pagecontent.style.height=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, true) + "px";
					}
				}
		    	});
		}
		if (home && home == true) {
			fbbox[0].className = 'fbbox';
			if (fbboxesBig.length == 1) {
				fbboxesBig[0].className = 'fbboxbig';
			}
		
		} else {
			var mpopen = getCookie("mpopen");
			var b_open = mpopen == null ? top.FBopen : (mpopen == "true");
			if (!b_open) {
				fbboxesPushin[0].className = 'fbbox-pushout';
				fbboxesContentBg[0].style.display = 'none';
				fbboxesContent[0].style.display = 'none';
				if(fbboxesVisual.length == 1){fbboxesVisual[0].style.display = 'none';}
				if(fbboxesInloggenLabel.length == 1){fbboxesInloggenLabel[0].style.display = 'block';}
				if(fbboxesInloggen.length == 1){fbboxesInloggen[0].style.display = 'none';}
				if(fbboxesOpacitylayer.length == 1){fbboxesOpacitylayer[0].style.display = 'none';}
				if(fbboxesLoginlayer.length == 1){fbboxesLoginlayer[0].style.display = 'none';}
				if(fbboxesSluit.length == 1){fbboxesSluit[0].style.display = 'none';}
				
				if ((seealsoblockspacetop) && (!(dashboarddiv))){
					seealsoblockspacetop.style.height= 33 + "px";
				}				
				if((strSeeAlsoHeight > 0) && (strPagecontent > 0) && (bExtraIframe)){
					pagecontent.style.minHeight=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, false) + 50 + "px";
					pagecontent.style.height=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, false) + 50 + "px";
					if (seealsoDivBot.length == 0){
						var seealsoDivBot = document.createElement('div');
						seealsoDivBot.setAttribute('id','');
						seealsoDivBot.setAttribute('class','largeseealsobot');
						pagecontent.appendChild(seealsoDivBot);
					}
				}				
				if((strSeeAlsoHeight > 0) && (strPagecontent > 0) && (!(bExtraIframe))){
					pagecontent.style.minHeight=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, false) + "px";
					pagecontent.style.height=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, false) + "px";
				}
			} else {
				if (seealsoblock) seealsoblock.style.paddingTop = (fbboxesHeight-17) + "px";
				if ((seealsoblockspacetop) && (dashboarddiv)) 
				                seealsoblockspacetop.style.height=33+ "px";
				if ((seealsoblockspacetop) && (!(dashboarddiv))){
					seealsoblockspacetop.style.height= 74 + 'px';
				}				
				if((strSeeAlsoHeight > 0) && (strPagecontent > 0) && (bExtraIframe)){
					pagecontent.style.minHeight=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, true) + 50 + "px";
					pagecontent.style.height=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, true) + 50 + "px";
					if (seealsoDivBot.length == 0){
						var seealsoDivBot = document.createElement('div');
						seealsoDivBot.setAttribute('id','');
						seealsoDivBot.setAttribute('class','largeseealsobot');
						pagecontent.appendChild(seealsoDivBot);
					}
				}
				if((strSeeAlsoHeight > 0) && (strPagecontent > 0) && (!(bExtraIframe))){
					pagecontent.style.minHeight=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, true) + "px";
					pagecontent.style.height=setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, true) + "px";
				}
			}
		}
	}
}

function setPageContentDivHeight(fbboxesHeight, strSeeAlsoHeight, strPagecontent, bLarge){
	if (bLarge){
		var strExtraOffsetHeight=(fbboxesHeight);
		var strExtraScaleHeight=(28);
	} else {
		var strExtraOffsetHeight=(0);
		var strExtraScaleHeight=(0);
	}
	var strSeeAlsoHeight=(strSeeAlsoHeight + strExtraOffsetHeight);
	var strPagecontent=(strPagecontent);
	var strScaleUp=(strSeeAlsoHeight - strPagecontent);
	if (strScaleUp > 0){
		var pageHeight=(strPagecontent + strScaleUp + strExtraScaleHeight);
		return pageHeight;
	} else {
		if (strPagecontent <= 640){
			var pageHeight=(640);
			return pageHeight;
		} else{
			return (strPagecontent);
		}
		
	}
}

function BBfill (home) {
	if (document.getElementById('bb_login')) {
		fbFrame = new RPCFrame(window);
		if (home) { fbFrame.setLocation('/travel/dk_en/business/bluebiz_/bluebiz.htm?redirect=no&pageID=' + window.pageID + '', BBfillItHome); }
		else { fbFrame.setLocation('/travel/dk_en/business/bluebiz_/bluebiz.htm?redirect=no&pageID=' + window.pageID + '', BBfillIt); }
                                initBlueBizAppFrame();
	}
}
function BBfillIt () {
	var sUserName = readCookie("bbloginname");
	var sChecked = readCookie("rememberbblogin");
	document.getElementById('bb_login').innerHTML = fbFrame.getHTMLById('content').innerHTML;
	BBLoggedfill();
	var oForm = document.getElementById("bbloginbox");
	if (oForm != null) {
		if ((sUserName != null) && (sUserName != '')) { 
			oForm.elements["username"].value = sUserName;
		}
		if ((sChecked != null) && (sChecked == 'false')) {
			oForm.elements["rememberbblogin"].checked = false;
		}
	}
	toggleMilesPlus();
	try {
		if (bluebiz != undefined) checkBB();
	} catch (e) {}
}
function BBfillItHome () {
	document.getElementById('bb_login').innerHTML = fbFrame.getHTMLById('content').innerHTML;
	document.getElementById('bottom').innerHTML = '';
	BBLoggedfill();
}
function BBLoggedfillIt() {
	document.getElementById('login-status').innerHTML = fbFrame.getDocument().innerHTML;
}
function BBLoggedfill () {
	if (document.getElementById('login-status')) {
		fbFrame = new RPCFrame(window);
		try{
		fbFrame.setLocation("/le2/passage/noseb2b/company/CompanyProfile/MemberInfo", BBLoggedfillIt);
		} catch (e) { }
	}
}
function loadNav() {
	if (document.getElementById('navlogo')) {
		new Navigation('navigation', 'navopen', document.getElementById('navigation').innerHTML);
	}
	else {
		/* Prevent double loading, since older jsps, still load the navigation with a setTimeout */
		if (!navFrame && document.getElementById('navigation')) {
			navFrame = new RPCFrame(window);
			navFrame.setLocation('/travel/dk_en/navigation.html', initNavigation);
			try {
				clearInterval(n);
				} catch (e) {
			}
		}	
		else {
			return false;
		}
	}	
}
function initNavigation () {
	new Navigation('navigation', 'navopen', navFrame.getHTMLById('navcontent').innerHTML);
}
function isChild(ancestor, candidate) {
	if (!ancestor || !ancestor.parentNode || !candidate) return false;
	while (candidate && candidate != ancestor.parentNode) {
		if (candidate == ancestor) return true;
		try {
			candidate = candidate.parentNode;
		} catch (c) {return false}
	}
}
function createContextFunction(context, method, method2) {
	return (function(x){
		method = (method == "post") ? method2 : method;
		eval("context."+method+"(x)");
		return false;
	});
}
function initSpecials() {
	var entries = document.getElementsByTagName('div');
	for (var i = 0; i < entries.length; i++) {
		if (entries[i].className == 'specials') {
			var specials = entries[i].getElementsByTagName('li');
			for (var j = 0; j < specials.length; j++) {
				if (specials[j].getElementsByTagName('a').length > 0)
				{
					specials[j].link = specials[j].getElementsByTagName('a')[0].href;
					specials[j].getElementsByTagName('a')[0].removeAttribute("href");
					if (specials[j].getElementsByTagName('a')[0].target=='_blank')
						specials[j].onclick = function () {window.open(this.link)};
					else
						specials[j].onclick = function () {document.location.href = this.link};
				}
				specials[j].onmouseover = function () {this.className = "over"}
				specials[j].onmouseout = function () {this.className = ""};
			}
		}
	}
}
function initSpecials_mp() {
	var entries = document.getElementsByTagName('div');
	for (var i = 0; i < entries.length; i++) {
		if (entries[i].className == 'specials_jffp') {
			var specials = entries[i].getElementsByTagName('li');
			for (var j = 0; j < specials.length; j++) {
				specials[j].link = specials[j].getElementsByTagName('a')[0].href;
				specials[j].getElementsByTagName('a')[0].removeAttribute("href");
				specials[j].onclick = function () {document.location.href = this.link};
				specials[j].onmouseover = function () {this.className = "over"}
				specials[j].onmouseout = function () {this.className = ""};
			}
		}
	}
}
function setTriggers() {
	var entries = document.getElementsByTagName('div');
	for (var i = 0; i < entries.length; i++) {
		if (entries[i].className.indexOf('TRIG') != -1) {
			entries[i].outline = entries[i].getElementsByTagName('div')[0];
			// create an exception for specials trigger
			if(entries[i].outline.className.indexOf('specials') == -1) {
				entries[i].link = entries[i].getElementsByTagName('a')[0];
				entries[i].onmouseover = function (e) {
					this.outline.oldClassName = this.outline.className;
					this.outline.className += "over";
                                                                                if (this.className.indexOf('widetrigger_pic') != -1 ) return;
					this.className += "  TRIGOVER";
				}
				entries[i].onmouseout = function (e) {
					this.outline.className = this.outline.oldClassName;
                                                                                if (this.className.indexOf('widetrigger_pic') != -1 ) return; 
					this.className = this.className.replace(" TRIGOVER","")
				}
				entries[i].onclick = function () {
					if (this.className.indexOf('newWin') != -1) {
						if (this.className.indexOf('KANA') !=-1) {
							window.open(this.link,'kana','width=400,height=300');
						}
						else if (this.className.indexOf('LSW') !=-1) { //local shop window
							window.open(this.link,'lsw','width=815,height=600,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,status=yes');
						}
						else {
							window.open(this.link);
						}	
					}
					else {
						document.location.href = this.link;
					}
				}
			}
		}
	}
}
function setTriggersHome() {
	var entries = document.getElementsByTagName('div');
	for (var i = 0; i < entries.length; i++) {
		if (entries[i].className.indexOf('TRIG') != -1) {
			entries[i].link = entries[i].getElementsByTagName('a')[0];
			entries[i].onmouseover = function (e) {
				if (this.className.indexOf('widetrigger_pic') != -1 ) return;
				this.className += " TRIGOVER";
			}
			entries[i].onmouseout = function (e) {
				if (this.className.indexOf('widetrigger_pic') != -1 ) return;
				this.className = this.className.replace(" TRIGOVER","");
			}
			entries[i].onclick = function () {
				if (this.className.indexOf('newWin') != -1) {
					if (this.className.indexOf('KANA') !=-1) {
						window.open(this.link,'kana','width=400,height=300');
					}
					else if (this.className.indexOf('LSW') !=-1) { //local shop window
						window.open(this.link,'lsw','width=815,height=600,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,status=yes');
					}
					else {
						window.open(this.link);
					}
					this.link.disabled = true;
				}
				else {
					document.location.href = this.link;
				}
			}
		}
	}
}
function setPromos() {
	var entries = document.getElementsByTagName('div');
	for (var i = 0; i < entries.length; i++) {
		if (entries[i].className.indexOf('nonair') != -1) {
			entries[i].outline = entries[i].getElementsByTagName('span')[0];
			entries[i].link = entries[i].getElementsByTagName('a')[0];
			entries[i].onclick = function () {document.location.href = this.link};
			entries[i].onmouseover = function (e) {
				this.outline.oldClassName = this.outline.className;
				this.outline.className += "over";
                                                                if (this.className.indexOf('widetrigger_pic') != -1 ) return;
                       			this.className += "  TRIGOVER";
			}
			entries[i].onmouseout = function (e) {
				this.outline.className = this.outline.oldClassName;
                                                                if (this.className.indexOf('widetrigger_pic') != -1 ) return; 
				this.className = this.className.replace(" TRIGOVER","")
			}
		}
	}
}

function toggleMilesPlus() {
	var miles = document.getElementById('mpopen');
	var milesplusblock = document.getElementById('jffpcontentcontainer');
	var seealsoblock = document.getElementById('seealso');
                var contentblock = document.getElementById('contentblock');
                var recent= document.getElementById('recent');
                var seealsobot= document.getElementById('seealsobot');
                var seealsoblockspacetop= document.getElementById('seealsoblockspacetop');
                var seealsoblocknewtop= document.getElementById('seealsoblocknewtop');
// mf 03/07 - in case no seealsoblock is present, then set seealsoblock to recent. this feature enables 
// mf 03/07 - the overview newsblock to also shift along with the FBlogging box 
// mdijk 05/05 - ALWAYS CHECK IF AN OBJECT EXISTS BEFORE ADDRESSING IT!!!!!!! In this case check if contentblock exists 
                if (!(seealsoblock) && (contentblock)){
                     contentblock.style.width=745+'px';}
                if (!seealsoblocknewtop) {
                    if(contentblock && seealsobot) {
                       contentblock.style.background='white';
                       seealsobot.style.background='white';
                    }
                }

                if (!(seealsoblock))
                {
                    seealsoblock = document.getElementById('recent');

                   }        
	if (milesplusblock != null) {
		milesplusblock.style.display = "none";
		var milesclose = document.getElementById('bottom');
		miles.onclick = function() {
			setCookie("mpopen", "true", 0);
			if (milesplusblock.style.display == 'none') {
				milesplusblock.style.display = 'block';
                                                                if (seealsoblock) seealsoblock.style.paddingTop = (milesplusblock.offsetHeight- 35) + "px";
if (seealsoblockspacetop) { seealsoblockspacetop.style.height= 17 + "px";}

			} else {
				milesplusblock.style.display = 'none';
				if (seealsoblock) seealsoblock.style.paddingTop = "0";
if (seealsoblockspacetop) { seealsoblockspacetop.style.height= "0";}


			}
		}
		milesclose.onclick = function() {
			setCookie("mpopen", "false", 0);
			if (milesplusblock.style.display == 'none') {
				milesplusblock.style.display = 'block';
				if (seealsoblock) seealsoblock.style.paddingTop = (milesplusblock.offsetHeight - 35) + "px";
if (seealsoblockspacetop) {seealsoblockspacetop.style.height= 17 + "px";}



			} else {
				milesplusblock.style.display = 'none';
				if (seealsoblock) seealsoblock.style.paddingTop = "0";
if (seealsoblockspacetop) { seealsoblockspacetop.style.height= "0";}


			}
		}
		var mpopen = getCookie("mpopen");
		var b_open = mpopen == null ? top.FBopen : (mpopen == "true");
		if (b_open) {
			milesplusblock.style.display = 'block';
			if (seealsoblock) seealsoblock.style.paddingTop = (milesplusblock.offsetHeight - 35) + "px";
if (seealsoblockspacetop) { seealsoblockspacetop.style.height= 17 + "px";}
		}
	}
}
function addEventHandler(element, type, handler) {
	try {
		element.addEventListener(type, handler, false);
	} catch(inferiorBrowserException) {
		if(element.attachEvent) 
			element.attachEvent('on'+type, handler);
		else 
			element['on'+type] = handler;
	}
	return [element, type, handler];
}
function isSafari() {
	return (/safari/i).test(navigator.userAgent);
}

function removeEventHandler(o, eventName, handler) {
	if (o.removeEventListener) {
		o.removeEventListener(eventName, handler, true);
	} else {
		o.detachEvent("on"+eventName, handler);
	}
}
function cancelEvent(e) {
	try {
		e.preventDefault();
		e.stopPropagation();
	} catch (someException) {
		e.cancelBubble = true;
		e.returnValue = false;
	}
	if (isSafari()) {
		var target = e.target;
		while (target.nodeType > 1) target = target.parentNode;
	 	if (/^a$/i.test(target.nodeName)) {
	 		target.onclick = function() {
				return false;
			};
		}
	}
	return false;
}

function calculateTop(object) {if (object) return object.offsetTop + calculateTop(object.offsetParent); else return 0;}
function calculateLeft(object) {if (object) return object.offsetLeft + calculateLeft(object.offsetParent); else return 0;}

function scaleFrame() {
	var f = document.getElementById('extFrame');
	var top;
	top = calculateTop(f);
	f.style.height = getWindowHeight() - top + "px";
	document.body.style.overflow = "hidden"; // for firefox and mozilla
	document.body.parentNode.style.overflow = "hidden"; // for ie
}
function getWindowHeight() {
var windowHeight=0;
	if (typeof(window.innerHeight)=='number') {
		windowHeight=window.innerHeight;
	} else {
		if (document.documentElement&&document.documentElement.clientHeight) {
			windowHeight=document.documentElement.clientHeight;
		} else if (document.body&&document.body.clientHeight) windowHeight=document.body.clientHeight;
	}
	return parseInt(windowHeight);
}
function setOtherKLMSites() {
	var s = document.getElementById('otherKLMsites');
	if (s) {
		s.onchange = function () {
			var strArr = this.options[this.selectedIndex].value.split("|");
			if (strArr[0] != "#") {
				if (strArr[1] == "New window" || strArr[1] == "Popup") {
					window.open(strArr[0],"_blank");
				} else {
					document.location.href = strArr[0];
				}
			}
		}
	}
}

function logOutJFFP () {
	deleteCookie('jffp');
	var location = '/travel/logon/dk_en?logOut=true';
	if (typeof(currentDashboard) != "undefined")
		if (currentDashboard != null)
			location += "&db=" + currentDashboard.selectedTab;
	document.location.href = location
}
function checkBB () {
	if (getCookie('klmcomcaas') == 'b2b') {
		document.getElementById('loginbar').style.display = 'none';
		document.getElementById('loggedinbar').style.display = 'block';
	} else {
		document.getElementById('loginbar').style.display = 'block';
		document.getElementById('loggedinbar').style.display = 'none';
	}
}
function checkLoggedin () {
	if (getCookie('jffp')) {
		if (getCookie('jffp').length > 10) {
			return true;
		}
	}
	return false;
}

function checkLogin () {
	if (getCookie('jffp')) {
		if (getCookie('jffp').length > 10) {
			document.getElementById('IN').style.display = 'block';
		} else {
			document.getElementById('OUT').style.display = 'block';
		}
	} else {
		document.getElementById('OUT').style.display = 'block'
	}
}

function initConditions() {
	var entries = document.getElementsByTagName('a');
	for (var i = 0; i < entries.length; i++) {
		if (entries[i].className == 'CONDITIONS') {
			entries[i].layer = entries[i].parentNode.getElementsByTagName('div')[0];
			entries[i].container = entries[i].parentNode.parentNode.parentNode.parentNode.parentNode;
			entries[i].layer.closer = entries[i].layer.getElementsByTagName('div')[0];
			entries[i].layer.closer.container = entries[i].container;
			entries[i].layer.closer.onclick = function () {
				this.parentNode.style.display = 'none';
				//this.container.style.position = 'static';
			}
			entries[i].onclick = function () {
				closeOthers();
				//this.container.style.position = 'relative';
				this.layer.style.display = 'block';
				var high = this.layer.offsetHeight;
				var newY = 0 - high + 'px';
				this.layer.style.marginTop=newY;
			}
		}
	}
}
function closeOthers () {
	var entries = document.getElementById('content').getElementsByTagName('div');
	for (var i = 0; i < entries.length; i++) {
		if (entries[i].className == 'conditionslayer')
			entries[i].style.display = 'none';
		if (entries[i].className == 'webawards')
			entries[i].style.position = 'static';
	}
}
function initWABanner () {
    var wa = document.getElementById('webawards');
    if (wa) {
        var anchors = wa.getElementsByTagName('a');
        if (anchors.length) {
            wa.link = anchors[0].href;
            wa.anchorfound = true;
            anchors[0].onclick = function() {wa.anchorfound = false;}
            wa.onclick = function () { 
                        if (wa.anchorfound) {
                                     document.location.href = this.link;
                        }else{
                                     wa.anchorfound = true;
                        } 
            }
        }
    }
}
function milesPlusLogon(){
	var strLocation;
	strLocation = "https://" + document.location.hostname + "/travel/logon/dk_en?forwardurl=/dk_en";
	if (typeof(currentDashboard) != "undefined") {
		if (currentDashboard != null) {
			strLocation += "?db=" + currentDashboard.selectedTab;
		}
	}
	document.forms.frmJFFP.action=strLocation;
	document.forms.frmJFFP.submit();
}

function checkBrowser() {
	if (getCookie('disableUnsupportedBrowserRedirect')){
                                return;
                }
	var browser = 'unknown';
	browser = getBrowser();
	if ((browser == 'TUX_FF') || (browser == 'TUX_MOZ') || (browser == 'TUX_OP') || (browser == 'MAC_OP') || (browser == 'WIN_OP') || (browser == 'WIN_IE8') ||  (browser == 'WIN_IE7') || (browser == 'WIN_IE6') || (browser == 'WIN_IE55') || (browser == 'WIN_IE50') || (browser == 'WIN_MOZ')|| (browser == 'WIN_FF') || (browser == 'MAC_SAF') || (browser == 'MAC_FF') || (browser == 'MAC_MOZ') || (browser = 'WIN_CHR') || (browser = 'MAC_CHR')|| (browser = 'TUX_CHR')) {
		//browser ok, so to 'normal' site
		return;
	}
	else {
		//wrong browser, so to 'browsersupport' page
		document.location.href = '/travel/klm_splash/browsersupport.html';
	}
}
function getParameter ( queryString, parameterName ) {
	var parameterName = parameterName + "=";
	if ( queryString.length > 0 ) {
		begin = queryString.indexOf ( parameterName );
		if ( begin != -1 ) {
			begin += parameterName.length;
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 ) {
				end = queryString.length
			}
			return unescape ( queryString.substring ( begin, end ) );
		}
	return null;
	}
}
function getBrowser () {
	var mvIndex;
	var mozVers;
	var os = navigator.platform.toLowerCase(); 
	var agt = navigator.userAgent.toLowerCase(); 
	var ver = navigator.appVersion.toLowerCase();
	
	if (os.indexOf('win') != -1) {
		if (agt.indexOf("opera")!=-1) return "WIN_OP";
		else if (agt.indexOf("msie 8.0")!=-1) return "WIN_IE8";
		else if (agt.indexOf("msie 7.0")!=-1) return "WIN_IE7";
		else if (agt.indexOf("msie 6.0")!=-1) return "WIN_IE6";
		else if (agt.indexOf("msie 5.5")!=-1) return "WIN_IE55";
		else if (agt.indexOf("msie 5.0")!=-1) return "WIN_IE50";
		else if (agt.indexOf("netscape")!=-1) return "Netscape";
		else if (agt.indexOf("firefox")!=-1) return "WIN_FF";
		else if (agt.indexOf("chrome")!=-1) return "WIN_CHR";
		else if (agt.indexOf("mozilla")!=-1) {
			var mvIndex = agt.indexOf('; rv:1.');
			var mozVers = agt.substr(mvIndex + 7, 1); 
			if (mozVers > 3) return "WIN_MOZ";
		}
	}
	else if (os.indexOf('mac') != -1) {
		if (agt.indexOf("opera")!=-1) return "MAC_OP";
		else if (agt.indexOf("safari")!=-1) {
			var safIndex = agt.indexOf('safari/');
			var safVers = agt.substr(safIndex + 7, 3);
			if (safVers >= 110) return "MAC_SAF";
		}
		else if (agt.indexOf("netscape")!=-1) return "Netscape";
		else if (agt.indexOf("firefox")!=-1) return "MAC_FF";
		else if (agt.indexOf("mozilla")!=-1) {
			var mvIndex = agt.indexOf('; rv:1.');
			var mozVers = agt.substr(mvIndex + 7, 1); 
			if (mozVers > 3) return "MAC_MOZ";
		}
		else if (agt.indexOf("chrome")!=-1) return "MAC_CHR";
	}
	else {
		if (agt.indexOf("opera")!=-1) return "TUX_OP";
		else if (agt.indexOf("netscape")!=-1) return "Netscape";
		else if (agt.indexOf("firefox")!=-1) return "TUX_FF";
		else if (agt.indexOf("chrome")!=-1) return "TUX_CHR";
		else if (agt.indexOf("mozilla")!=-1) {
			return "TUX_MOZ";
		}
	}	
}

function checkReturnKey(event, varForm, blnMilesPlusLogon)
{
	var key;
	if(window.event)
		key = window.event.keyCode;     //IE
	else
		key = event.which;     //firefox

	if (key == 13)
	{
		if (blnMilesPlusLogon)
			milesPlusLogon();
		else
		{
			if(varForm!=null)
				varForm.submit();
			return true; // handle submittingoutside after exiting this function if varForm==null
		}
	}
	return false;
}

function include_css(uri, media) {
    var head = document.getElementsByTagName('head').item(0);
    var link = document.createElement('link');
    link.setAttribute('type', 'text/css');
    link.setAttribute('rel', 'stylesheet');
    link.setAttribute('href', uri);
    if (media)
        link.setAttribute('media', media);
    head.appendChild(link);
    return false;
}

function include_jscript(uri) {
    var head = document.getElementsByTagName('head').item(0);
    var script = document.createElement('script');
    script.setAttribute('type', 'text/javascript');
    script.setAttribute('src', uri);
    head.appendChild(script);
    return false;
}

function preloadImages(){
	var strLocation = document.location;
	if (strLocation.toString().indexOf('ebt/ebt7') > -1){
		image1 = new Image();
		image1.src = "/travel/dk_en/images/InformationMouseover_tcm83-125620.jpg";
		image2 = new Image();
		image2.src = "/travel/dk_en/images/NeedhelpMouseover_tcm83-125623.jpg";
		image3 = new Image();
		image3.src = "/travel/dk_en/images/Information_NL_2b_tcm83-125617.jpg";
		image4 = new Image();
		image4.src = "/travel/dk_en/images/Start-buttonENMouseover_tcm83-125625.jpg";
	}
}
var first = true;
function formshowhideICIinputField(inputValue) {
	if ( first )
	{
		formshowhideICIvalue(inputValue);
		selectButton(inputValue);
	}
}

function checkRadio(buttons) {
	var radioEmpty = false;
		if (buttons[i].checked) {
		radioEmpty = true;
	}
}

function formshowhideICIradioBtn(radio) {
	formshowhideICIvalue(radio.value);
}

function selectButton(inputValue) {
	switch (inputValue) {
		case 'ET':
			document.getElementById("eticket_input").checked = true;
		break;
		case 'PNR':
			document.getElementById("booking_input").checked = true;
		break;
	}
}

function formshowhideICIvalue(radioValue) {
	if ( first )
	{
		first = false;
	}
	switch (radioValue) {
		case 'ET':
			var objTextBox = document.getElementById("eticketnumbDiv");
			objTextBox.className = "textbox1";
		break;
		case 'PNR':
			var objTextBox = document.getElementById("eticketnumbDiv");
			objTextBox.className = "textbox2";
		break;
		}
		var objInputField = document.getElementById("eticketnumb");
		var attrDisabled = objInputField.attributes["disabled"];
			if ( attrDisabled ) {
				objInputField.removeAttribute('disabled');
		}
		hideLayer();
		clearinputText(objInputField);
		objInputField.focus();
}

var el = window;
if (el.addEventListener)
{
	el.addEventListener('load', addFBJavascripts, false); 
}
else if (el.attachEvent)
{
	el.attachEvent('onload', addFBJavascripts);
}


function addFBJavascripts()
{
	var sPath = window.location.pathname;
	var sPageName = sPath.substring(sPath.lastIndexOf('/') + 1);
		
	if ((sPageName.substring(sPageName.length - 5, sPageName.length).toUpperCase() != ".HTML") &&  (document.getElementById("jffp_login")))
	{
		var aScriptURLs = [
			'/travel/widgetbroker/interface/Widget.js' ,
			'/travel/widgetbroker/engine.js',
			'/travel/widgetbroker/util.js'
			];
		YAHOO.util.Get.script(aScriptURLs, { onSuccess: successFBJS  });
	}
	
}


var successFBJS = function(oData) 
{
	
	var scripts = document.getElementsByTagName("script");
	for (var i = 0; i < scripts.length; i++)
		eval(scripts[i]);

	if (getCookie("jffp") && (!(document.getElementById("fbbox-username"))))
                	requestmmbwidget ();

}




function requestmmbwidget ()
{

                var sBVSessionId =  getURLParameters("FBSessionID");
	
	
	if (sBVSessionId == "")
	{
		if (getCookie("jffp"))
			sBVSessionId = getCookieURLParameters ("FBSessionID", "?" + getCookie("jffp"));
	}

	var sBVEngineId = getURLParameters("FBCloneID")
	if (sBVEngineId == "")
	{
		if (getCookie("jffp"))
			sBVEngineId = getCookieURLParameters ("FBCloneID", "?" + getCookie("jffp"));
	}

 	var SesEngId = { 
 			"BV_SessionID" : sBVSessionId, 
   			"BV_EngineID" : sBVEngineId  
		}
   
   	var WidgetRequest = {
   		country : "dk",
   		lang : "en",
   		pos : "dk",
   		type : "mmb",
   		attributes : SesEngId
   		}


	dwr.engine.setTimeout(15000);
 	dwr.engine.setErrorHandler(HandleMMBError);
	Widget.getWidget(WidgetRequest, HandleMMBDataResponse);
	
}


function getURLParameters(name)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );

	var results = regex.exec( window.location.href );

	if( results == null )    
		return "";
	else   
		return results[1];
}


function getCookieURLParameters(name, URL)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );

	var results = regex.exec(URL);

	if( results == null )    
		return "";
	else   
		return results[1];
}


function HandleMMBError()
{
	var diverrmsg = document.getElementById("fberrormsg");
	
	if (diverrmsg)
	{
		diverrmsg.style.display = "";

		var divimg = document.getElementById("fbwaiting");
		if (divimg)
			divimg.style.display = "none";
	}
	else
	{
		if (!(document.getElementById("fbbox-username")))
			setTimeout ("WaitForJFFPAndFill('', 1)", 1000);
	}
}



function HandleMMBDataResponse(strWidgetResponse)
{
	if ((strWidgetResponse == null) || (strWidgetResponse == ""))
	{
			var diverrmsg = document.getElementById("fberrormsg");
			if (diverrmsg)
			{
				diverrmsg.style.display = "";

				var divimg = document.getElementById("fbwaiting");
				if (divimg)
					divimg.style.display = "none";
			}
			else
			{
				if (!(document.getElementById("fbbox-username")))
					setTimeout ("WaitForJFFPAndFill('', 1)", 1000);
			}
			
	}
	else
	{
		var div = document.getElementById("fbmmbnextflight");
		if (div)
		{
			div.innerHTML = strWidgetResponse;
		}
		else
		{
			if (!(document.getElementById("fbbox-username")))
				setTimeout ("WaitForJFFPAndFill('" + strWidgetResponse + "', 1)", 1000);
		}	
                 }
}

function WaitForJFFPAndFill(strWidgetResponse, iNoofAttempts)
{

	if (strWidgetResponse == "")
	{
			var diverrmsg = document.getElementById("fberrormsg");
			if (diverrmsg)
			{
				diverrmsg.style.display = "";


				var divimg = document.getElementById("fbwaiting");
				if (divimg)
					divimg.style.display = "none";
			}
			else if(iNoofAttempts <= 120)
			{
				iNoofAttempts = iNoofAttempts +1 ;
				setTimeout ("WaitForJFFPAndFill('', " + iNoofAttempts + ")", 1000);
			}
	}

	else
	{
		var div = document.getElementById("fbmmbnextflight");
		if (div)
		{
			div.innerHTML = strWidgetResponse;
		}
		else if(iNoofAttempts <= 120)
		{
			iNoofAttempts = iNoofAttempts +1 ;
			setTimeout ("WaitForJFFPAndFill('" + strWidgetResponse + "', " + iNoofAttempts + ")", 1000);
		}
	}

}


function hideLayer() {
	document.getElementById("eticketnumbDummyDiv").style.visibility = "hidden";
}

function clearinputText(el) {
	el.value='';
}