var ProfileHistoryListUrl="";
function showHistory(ClickElement, ShowElementName, UrlParameters){

	// Show What is my report
	document.getElementById('popup6').style.display = 'none';
	
	// Close "My page history" layers
	closeLayers1();

	if ( ShowElementName ) {
		var ShowElement=document.getElementById(ShowElementName);
		// If the container already is visible then hide it, else show it
		if( ShowElement.style.display!='none')
			ShowElement.style.display='none'; // Hide the container
		else {
			ShowElement.style.display=''; // Show the container, but set opacity to null
		}
	}
	if ( ProfileHistoryListUrl ) {
		var LoadContainer=document.getElementById('ProfileHistoryListLoading');
		
		var CallProfileHistoryListUrl=ProfileHistoryListUrl;
		var UpdateContainer=document.getElementById('ProfileHistoryList');

		if ( typeof(UrlParameters)=='undefined' ) UrlParameters="";
		if ( UrlParameters ) UrlParameters+='&';
		UrlParameters+="Timestamp="+((new Date())*1);

		if ( UpdateContainer ) {
			if ( UrlParameters ) {
				if ( CallProfileHistoryListUrl.indexOf('?')>-1 )
					CallProfileHistoryListUrl+='&'+UrlParameters;
				else 
					CallProfileHistoryListUrl+='?'+UrlParameters;
			}
			//alert("URL: "+CallProfileHistoryListUrl);
			AjaxUpdate(CallProfileHistoryListUrl, UpdateContainer, LoadContainer);
		}
	}
	if ( ClickElement ) ClickElement.blur(); // Blur the button
} // showHistory

function expButton(unblur,showWhich,closeWhich){

	// Close "Add to my report" layers
	closeLayers2();

	// Blur this button
	var unBlurMe = unblur.id;

	// Which pop up would we like to be shown?
	var showLayer = showWhich;
	
	// Which pop up would we like to be shown?
	var closeLayer = closeWhich;
	
	// Rule 1: Confirm must always be hidden when clicking AddToMyReport
	document.getElementById('popup4').style.display = 'none';
	
	
	if(document.getElementById(closeLayer).style.display == 'block'){
		document.getElementById(closeLayer).style.display = 'none';
	}

	// If the 'pop1container' container already 
	// is visible then hide it, else show it
	
	if(document.getElementById(showLayer).style.display == 'block'){
	
		// Hide the container
		document.getElementById(showLayer).style.display = 'none';
		document.getElementById(closeLayer).style.display = 'none';
	
	} else {
	
		// Show the container, but set opacity to null
		document.getElementById(showLayer).style.display = 'block';
	
	}
	
	// Remove blur from link
	document.getElementById(unBlurMe).blur();

}

function closeLayers1(){

	/* Close layers (triggered by expButton */
	
	document.getElementById('popup1').style.display = 'none';
	document.getElementById('popup2').style.display = 'none';
	document.getElementById('popup3').style.display = 'none';
	document.getElementById('popup4').style.display = 'none';

}

function closeLayers2(){

	/* Close layers (triggered by showHistory */
	
	document.getElementById('popup5').style.display = 'none';
	document.getElementById('popup6').style.display = 'none';

}

function closeLayers3(){

	// Close all layers
	if(document.getElementById('popup1')){document.getElementById('popup1').style.display = 'none';}
	if(document.getElementById('popup2')){document.getElementById('popup2').style.display = 'none';}
	if(document.getElementById('popup3')){document.getElementById('popup3').style.display = 'none';}
	if(document.getElementById('popup4')){document.getElementById('popup4').style.display = 'none';}
	if(document.getElementById('popup5')){document.getElementById('popup5').style.display = 'none';}
	if(document.getElementById('popup6')){document.getElementById('popup6').style.display = 'none';}

}

function showWhatIsMyReport(){

	// Remove myself
	document.getElementById('popup4').style.display = 'none';

	// show layer
	document.getElementById('popup1').style.display = 'block';
	document.getElementById('popup2').style.display = 'none';
	
	// Set cookie
	SetCookie('CookieWhatIsMyReport','CookieSet',exp);

}

function closeWhatIsMyReport(){

	// show layer
	document.getElementById('popup1').style.display = 'none';
	document.getElementById('popup2').style.display = 'block';

}

function showWhatIsMyPageHistory(){

	// Hide "My Report history"
	document.getElementById('popup5').style.display = 'none';
	
	// Show What is my report
	document.getElementById('popup6').style.display = 'block';
	
	// Set cookie
	SetCookie('AutoPlayWhatHistory','CookieSet',exp);

}

function CloseMyPageHistory(){
	
	document.getElementById('popup6').style.display = 'none';
	document.getElementById('popup5').style.display = 'block';

}

function CloseMyReport(){
	
	document.getElementById('popup1').style.display = 'none';
	document.getElementById('popup2').style.display = 'block';

}

function ToogleCollages(){

	// Toogle layers
	document.getElementById('sections-content').style.display = 'none';
	document.getElementById('sections-flash').style.display = 'block';

	// Change background
	if(document.getElementById('presentation3')){document.getElementById('presentation3').style.backgroundImage = 'url(/gfx/body_bg_pre4.gif)';}
	if(document.getElementById('presentation5')){document.getElementById('presentation5').style.backgroundImage = 'url(/gfx/body_bg_pre4.gif)';}

}

function reverseToogleCollages(){

	// Toogle layers
	document.getElementById('sections-flash').style.display = 'none';
	document.getElementById('sections-content').style.display = 'block';

	// Change background
	if(document.getElementById('presentation3')){document.getElementById('presentation3').style.backgroundImage = 'url(/gfx/body_bg_pre3.gif)';}
	if(document.getElementById('presentation5')){document.getElementById('presentation5').style.backgroundImage = 'url(/gfx/body_bg_pre3.gif)';}

}

// ******************************* WORKING ************************************

function reverseShowWhatIsMyPageHistory(){

	// Show What is my report
	document.getElementById('popup6').style.display = 'none';

	// Hide "My Report history"
	document.getElementById('popup5').style.display = 'block';

}

// ******************************* WORKING ************************************

function expandButton1(unblur,showWhich){

	// Blur this button
	var unBlurMe = unblur.id;

	// Which pop up would we like to be shown?
	var showLayer = showWhich;

	// If the 'pop1container' container already 
	// is visible then hide it, else show it
	
	if(document.getElementById('pop1container').style.display == 'block'){
	
		// Hide the container
		document.getElementById('pop1container').style.display='none';
	
	} else {
	
		// Show the container, but set opacity to null
		document.getElementById('pop1container').style.display='block';
		document.getElementById(showWhich).style.opacity = '0';
		
		// Fade in
		shiftOpacity(showWhich,1000);
	
	}
	
	// Show the disered layer
	document.getElementById(showWhich).style.display='block';
	
	// Remove blur from link
	document.getElementById(unBlurMe).blur();

}

function expandButton2(unblur,showWhich){

	// Blur this button
	var unBlurMe = unblur.id;

	// Which pop up would we like to be shown?
	var showLayer = showWhich;

	// If the 'pop1container' container already 
	// is visible then hide it, else show it
	
	if(document.getElementById('pop2container').style.display == 'block'){
	
		// Hide the container
		document.getElementById('pop2container').style.display='none';
	
	} else {
	
		// Show the container, but set opacity to null
		document.getElementById('pop2container').style.display='block';
		document.getElementById(showWhich).style.opacity = '0';
		
		// Fade in
		shiftOpacity(showWhich,1000);
	
	}
	
	// Show the disered layer
	document.getElementById(showWhich).style.display='block';
	
	// Remove blur from link
	document.getElementById(unBlurMe).blur();

}

/* Timer variable */
var timer;
var dontclose;
var todoClose;

function ButtonOver(parLayer){

	var MyLayer = parLayer;

	/* Show the filter */
	if(document.getElementById(MyLayer).style.display == 'block'){
		
		// Show or keep on showing container
		document.getElementById(MyLayer).style.display = 'block';
	}
	
	/* Clear timer */
	clearTimeout(timer)
	
	/* set var */
	dontclose = true;
	
}

function ButtonOut(parLayer){

	var MyLayer = parLayer;

	/* Tick the timer */
	timer = setTimeout("HideButtonOut();",2000);
	
	/* Layer to be closed */
	todoClose = MyLayer;
	
	/* set var */
	dontclose = false;
	
}

function HideButtonOut(){

	/* Show the filter */
	if (!dontclose){
		document.getElementById(todoClose).style.display = 'none';
	}
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 

function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 0, 100, millisec);
        //opacity(id, 100, 0, millisec); 
    } 
}

function GoToUrl(goToUrl){

	var urltogoto = goToUrl;
	
	// Send to url
	location.href = urltogoto;

}

/* Cookies
----------------------------------------------------------- */

var expDays = 14;
var exp = new Date();

exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {

var endstr = document.cookie.indexOf (";", offset);

if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;	
	var i = 0;

while (i < clen) {
	var j = i + alen;

		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
}
return null;
}

function SetCookie (name, value) {

	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {

	var exp = new Date();
	exp.setTime (exp.getTime() - 1);

	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function checkScene(){
	
	var favorite = GetCookie('identifier');
	
	if (favorite == null){
		//alert('Cookie has been set. Steen starts to speak..');
		SetCookie('identifier','frontSteen',exp);
	}else{
		// Redirect
		//alert('You have already seen this page. Steen speaks only if you active him..');
	}
	
}

function checkFrontpage(){
	
	var favorite = GetCookie('FrontpageCookie');
	
	if (favorite == null){
		//alert('Cookie has been set. Steen starts to speak..');
		SetCookie('FrontpageCookie','CookieSet',exp);
	}else{
		// Redirect
		//alert('You have already seen this page. Steen speaks only if you active him..');
	}
	
}

function sectionFlash(parSectionCookieName){

	var sectionCookieName = parSectionCookieName;
	
	/* Set new section cookie */
	SetCookie(sectionCookieName,'CookieSet',exp);

}

function setSparkling(){

	var sparkCounter = parseInt(GetCookie('sparkCount'));
	
	if( !sparkCounter ){
		// sparkCounter = 0, set value to 1
		sparkCounter = 1;
	}else{
		// sparkCounter is a number, add 1 to it
		sparkCounter+=1;
	}

	/* Set cookie information */
	SetCookie('sparkCount',sparkCounter,exp);
	
}

function dontShowAgain(parElement){

	var elementToHandle = parElement;

	if(document.getElementById(elementToHandle).className=='' || document.getElementById(elementToHandle).className=='off'){
	
		/* Set to checked, create cookie */
		document.getElementById(elementToHandle).src = '/gfx/dont_show_checked.gif';
		document.getElementById(elementToHandle).className = 'on';
		
		SetCookie('dontshowagain','true',exp);
		
	}else{
	
		/* Set to unchecked, die cookie die.. */
		document.getElementById(elementToHandle).src = '/gfx/dont_show_unchecked.gif';
		document.getElementById(elementToHandle).className = 'off';
		
		DeleteCookie('dontshowagain');
		
	}

}

function closeConfirm(){

	// Hide current
	document.getElementById('popup4').style.display = 'none';

}

function closeHistory(){

	// Hide current
	document.getElementById('popup5').style.display = 'none';
	if ( event ) event.cancleBubble=true;
}

function AddConfirm(){

	// User has clicked the add to my report, now hide the bar
	document.getElementById('popup2').style.display = 'none';
	
	// The glow effect needs to be removed as well
	document.getElementById('popup3').style.display = 'none';


	// Check status of "dont show again"
	var checkDontShowAgain = GetCookie('dontshowagain');

	// Have the user checked the "dont show again"
	if(checkDontShowAgain==null){
	
		/* User looooves the confirm page and want to see it again */
		document.getElementById('popup4').style.display = 'block';
		
		/* Set graphic to false */
		document.getElementById('DongShowAgain').src = '/gfx/dont_show_unchecked.gif';
		document.getElementById('DongShowAgain').className = 'off';
	
	} else {
	
		/* User dont want to see the confirm page */
		document.getElementById('popup4').style.display = 'none';
		
		/* Set graphic to true */
		document.getElementById('DongShowAgain').src = '/gfx/dont_show_checked.gif';
		document.getElementById('DongShowAgain').className = 'on';
	
	}

}


/* Glow effects (button1)
---------------------------------------------------------------------------*/

function ShowGlow(){

	// Show the glow effect
	document.getElementById('popup3').style.display = 'block';

}

function HideGlow(){

	// Show the glow effect
	document.getElementById('popup3').style.display = 'none';

}

/* Add to my report pop up - hover on the close cross
---------------------------------------------------------------------------*/

function closeLayerBtnOver(parElement,parLang){

	var elementToHandle = parElement;
	var elementLanguage = parLang;
	
	/* Change picture source */
	if(parLang == 'uk'){
		document.getElementById(elementToHandle).src = '/gfx/popup_close_hover_uk.gif';
	} else {
		document.getElementById(elementToHandle).src = '/gfx/popup_close_hover_dk.gif';
	}

}

function closeLayerBtnOut(parElement,parLang){

	var elementToHandle = parElement;
	var elementLanguage = parLang;
	
	/* Change picture source */
	if(parLang == 'uk'){
		document.getElementById(elementToHandle).src = '/gfx/popup_close_uk.gif';
	} else {
		document.getElementById(elementToHandle).src = '/gfx/popup_close_dk.gif';
	}

}

/* Popup and highlight handler scripts */
function GsOpenPopup(Url, Height, Width, Name) {
	if (!Height) Height=480;
	if (!Width) Width=714;
	Width=605;

	if (Width>screen.availWidth) Width=screen.availWidth;

	var x = Math.round((screen.width-Width)/2);
	var y = Math.round((screen.height-Height)/2);

	popupWindow=window.open(Url, '_blank','scrollbars=yes,width='+Width+',height='+Height+',left='+x+',top='+y+',location=no,menubar=no,resizable=no,titlebar=no,status=no,directories=no');
	//if (typeof(popupWindow)!="undefined") return false;
	//else return true;
	return false;
} // GsOpenPopup

function HandleWord(ObjectId) {
	var dimX, dimY, posX, posY;
	var varSettings;
	var TermsExplained;
	dimX = 480;
	dimY = 360;
	posX = Math.round((screen.width-480)/2);
	posY = Math.round((screen.height-360)/2);
	varSettings = 'toolbar=0,menubar=0,resizable=0,scrollbars=1,Width=' + dimX + ',Height=' + dimY + ',left=' + posX + ',top=' + posY;
	var wnd = window.open('/globalsite.aspx?ObjectId='+ObjectId,'NzGlossary',varSettings);
	wnd.focus();
} // HandleWord


/* Tab menu for Reporting updates frontpage */
function tabber(tabname) {
	var elms = document.getElementsByTagName("*");

	for(i=0;elms.length>i;i++) {
		if( elms[i].className.indexOf('TabsHeader')>-1 ) {
			try {
				elms[i].className='TabsHeader';
				document.getElementById('Tab'+tabname).className = 'TabsHeaderOver' ;
			} catch(e) {
				alert('Error block 1:\n'+e.message);
				return false;
			} // Change tabs
		}
	}
	  
	var tabelms = document.getElementsByTagName("*");

	for (i=0;tabelms.length>i;i++) {
		if(tabelms[i].className.indexOf('ShowHideTabs')>-1) {
			try {
				tabelms[i].style.display = 'none' ;
				document.getElementById('ShowHideTab'+tabname).style.display = 'block' ;
			} catch(e) {
				alert('Error block 2:\n'+e.message);
				return false;
			} // Change tabs block / none
		}
	}
} // tabber

var Try = {
	these: function() {
	var returnValue;
	
	for (var i = 0; i < arguments.length; i++) {
		var lambda = arguments[i];
		try {
			returnValue = lambda();
			break;
		} catch (e) {}
		}
		
		return returnValue;
	}
} // Try

function AjaxTransport() {
	return Try.these(
		function() {return new ActiveXObject('Msxml2.XMLHTTP');},
		function() {return new ActiveXObject('Microsoft.XMLHTTP');},
		function() {return new XMLHttpRequest();}
	) || false;
} // AjaxTransport

function AjaxUpdate(Url, Container, LoadContainer, ErrorContainer) {
    var AjaxTransportUpdate=AjaxTransport();
	if ( AjaxTransportUpdate ) {
		var UrlParameters='ajax=true';
/*		if ( Url.indexOf('?')>-1 ) {
			UrlParameters=Url.substr(Url.indexOf('?')+1);
			Url=Url.substr(0, Url.indexOf('?'));
		}*/
	    AjaxTransportUpdate.open('POST', Url, true);
	    AjaxTransportUpdate.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

		if ( typeof(LoadContainer)=='undefined' || !LoadContainer ) {
		    AjaxTransportUpdate.onreadystatechange = function() {
		        if ( AjaxTransportUpdate.readyState==4 ) {
					Container.innerHTML=AjaxTransportUpdate.responseText;
				}
		    }
		} else {
			LoadContainer.style.display='';
			Container.innerHTML='';
		    AjaxTransportUpdate.onreadystatechange = function() {
		        if ( AjaxTransportUpdate.readyState==4 ) {
					Container.innerHTML=AjaxTransportUpdate.responseText;
					LoadContainer.style.display='none';
				}
		    }
		}
	    AjaxTransportUpdate.send(UrlParameters); 
	}
} // AjaxUpdate
