// This method takes an IFrame object and resizes it based on its content
// This can only be applied to sites in the same domain
/*
window.onload = function()
{
	var iframes = document.getElementsByTagName("iframe");
	
	for (var i = 0; i < iframes.length; ++i)
	{		
		var iframe = iframes[i];
		iframe.resize = iframe_resize;
		iframe.loadContent = iframe_loadContent;
		iframe.loadStateChanged = iframe_loadStateChanged;
		iframe.contentLoaded = iframe_contentLoaded;
		
		iframe.resize();
	}
}

function iframe_resize()
{
	if (this.readyState && this.readyState != "complete")
	{
		return;
	}
	
	try 
	{
		this.loadContent();
	}
	catch (e) 
	{
		window.status = e.message;
	}
}

function iframe_loadContent()
{
	this.xmlhttp = null;
	
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
		this.xmlhttp = new XMLHttpRequest();
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if (this.xmlhttp != null)
	{
		var oThis = this;
		var e = function()
		{
			oThis.loadStateChanged();
		}

		this.xmlhttp.onreadystatechange = e;
		this.xmlhttp.open("GET", "/Site/Start.htm", true);
		this.xmlhttp.send(null);
	}
}

function iframe_loadStateChanged()
{
	// if xmlhttp shows "loaded"
	if (this.xmlhttp.readyState == 4)
	{		
		// if "OK"
		if (this.xmlhttp.status == 200)
		{
			// Create hidden frame if it's not there
			if (typeof this.hiddenFrame == "undefined")
			{
				this.hiddenFrame = document.createElement("iframe");
				this.hiddenFrame.style.left = 0;
				this.hiddenFrame.style.top = 0;
				this.hiddenFrame.style.position = "absolute";
				this.hiddenFrame.style.visibility = "hidden";
				document.body.childNodes[0].insertAdjacentElement("beforeBegin", this.hiddenFrame);
				this.hiddenFrame.src = "about:blank";
				
				var oThis = this;
				var e = function()
				{
					oThis.contentLoaded();
				}
				
				this.hiddenFrame.onreadystatechange = e;
			}
			
			// Write contents to the hidden frame
			try
			{
				if (this.hiddenFrame.contentDocument)
				{
					innerDoc = this.hiddenFrame.contentDocument;
				}
				else if (this.hiddenFrame.contentWindow && this.hiddenFrame.contentWindow.document)
				{
					innerDoc = this.hiddenFrame.contentWindow.document;
				}
			
				innerDoc.open();
				innerDoc.write(this.xmlhttp.responseText);
				innerDoc.close();
			}
			catch (e)
			{
				window.status = e.message;
			}
		}
		else
		{
			window.status = "Problem retrieving XML data";
		}
	}
}

function iframe_contentLoaded()
{
	if (this.hiddenFrame.readyState != "complete")
	{
		return;
	}
	
	// Turn off the ready state change
	this.hiddenFrame.onreadystatechange = null;
	
	if (this.hiddenFrame.contentDocument)
	{
		innerDoc = this.hiddenFrame.contentDocument;
	}
	else if (this.hiddenFrame.contentWindow && this.hiddenFrame.contentWindow.document)
	{
		innerDoc = this.hiddenFrame.contentWindow.document;
	}
	
	// Resize the style object, if it exists. Otherwise, resize the frame itself.
	objToResize = (this.style) ? this.style : this;

	// Resize the object to the scroll height of the inner document body. You may still have 
	// to add a 'fudge' factor to get rid of the scroll bar entirely. With a plain-vanilla 
	// iframe, I found Netscape needs no fudge, IE needs 4 and Opera needs 5... 
	// Of course, your mileage may vary.
	objToResize.width = innerDoc.body.scrollWidth;
	objToResize.height = innerDoc.body.scrollHeight + 5;
	
	var oThis = this;
	var f = function()
	{
		oThis.resize();
	}
	
	this.onreadystatechanged = f;
}
*/

// This method takes an IFrame object and resizes it based on its content
// This can only be applied to sites in the same domain
function ResizeIFrame( frame )
{
	try 
	{
		// Get the document within the frame. This is where you will fail with 'permission denied'
		// if the document within the frame is not from the same domain as this document.
		// Note: IE uses 'contentWindow', Opera uses 'contentDocument', Netscape uses either.
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;

		// Resize the style object, if it exists. Otherwise, resize the frame itself.
		objToResize = (frame.style) ? frame.style : frame;

		// Resize the object to the scroll height of the inner document body. You may still have 
		// to add a 'fudge' factor to get rid of the scroll bar entirely. With a plain-vanilla 
		// iframe, I found Netscape needs no fudge, IE needs 4 and Opera needs 5... 
		// Of course, your mileage may vary.
		
		// "+px". n.a.v. incident #205865
		objToResize.height = innerDoc.body.scrollHeight + 5 + "px";
	}
	catch( e ) 
	{
		window.status = e.message;
     
		// IE only, usefull only when cross-site scripting

//		ITOKKEN 20080910: I'm not sure whether this'll work. 
//		IE needs "contentWindow" object with iframe heights.
//		Let's just Comment it out
//		targetHeight = frame.document.body.scrollHeight;
//		frame.style.height = targetHeight.toString() + "px";

//		ITOKKEN 20080910: This might do ...
//		frame.style.height = frame.contentWindow.body.scrollHeight + "px";
//		ITOKKEN 20090226: previous line commented out due to errormessage on page
	}
}

// This method is used to call into the MCMS link editor and retrieve the correct properties
function MCW_CreateLink(linkLabel, linkValue, linkTarget)
{
	if (linkLabel.value == "")
	{ 
		alert("please first enter a link text"); 
		return;
	}
	
	var args = new Object();
	args.Href = linkValue.value;
	args.Target = linkTarget.value;
	
	var strPath = IDS_FRAMEWORK_NEW_VIRTUAL_PATH + "/Dialogs/HLink/Hlink.aspx";
	var strDlgRet = window.showModalDialog( strPath, args, "dialogWidth:650px;dialogHeight:350px;resizable;status:no;help:no" );
	
	if ( typeof(strDlgRet) == "undefined" || strDlgRet == null )
	{
		return;
	}
	
	linkValue.value = strDlgRet.Href;
	linkTarget.value = strDlgRet.Target;
}


// This method opens a pop-up window for the print version of a page
function openForPrint( url )
{
	wnd = window.open( url, "printwindow", "height=550,width=600,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resize=no" );
	wnd.focus();
}

// This method opens a pop-up window allowing the current page to be sent as a link
function openForEmail( url )
{
	wnd = window.open( url, "printwindow", "height=550,width=600,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resize=no" );
	wnd.focus();
}

// This method opens a pop-up window allowing a user to select a channel as a source for an overview
function openChannelPickerWindow( controlID )
{
	var popopurl = "/Site/Presentation/Functional/Placeholders/Dialogs/PageMoveDlg.aspx?NRMODE=Update&FRAMELESS=true&controlID=" + escape( controlID );
	wnd = window.open( popopurl, "popupwindow", "height=550,width=600,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resize=no" );
	wnd.focus();
}

// This method takes a dropdownlist and navigates to its selected value as a url
function gotoDropDownURL( dropDownList ) 
{
	// Check for an empty value before redirecting
	if( dropDownList.options[dropDownList.selectedIndex].value != "" )
	{
		window.location.href = dropDownList.options[dropDownList.selectedIndex].value;
	}
}

// This method takes a url and keywords and redirects to the search page
function gotoSearchURL( searchUrl, keywordsID ) 
{
	var keywords = document.getElementById(keywordsID);
	
	// Check for an empty value before redirecting
	if( keywordsID != null && searchUrl != "" )
	{
		window.location.href = searchUrl + "?Query=" + keywords.value;
	}
}

// This method creates an array with the specified dimensions
function MultiDimensionalArray( iRows, iCols ) 
{
	var i; 
	var j; 
	var a = new Array( iRows ); 
	
	for( i = 0; i < iRows; i++ ) 
	{ 
		a[i] = new Array( iCols ); 
		for( j = 0; j < iCols; j++ ) 
		{ 
			a[i][j] = ""; 
		} 
	}
	
	return( a ); 
}

// This method handles a keypress in the website and triggers the correct button
function handleKey( e, targetButtonID )
{
	if( !e )
	{
		e = window.event;
		var targ = e.srcElement;
	}
	else
	{
		var targ = e.target;
	}
	
	if( e.keyCode )
	{ 
		keypress = e.keyCode; 
	} 
	else
	{ 
		keypress = e.which; 
	}
	
	if( keypress == 13 )
	{
		var button = document.getElementById( targetButtonID );
		
		if( button.click )
		{
			button.click();
		}
		else
		{
			var action = button.toString();
			if( action.indexOf( 'javascript:' ) != -1 )
			{
				eval( action );
			}
		}
		
		return false;
	}
	else
	{	
		return true;
	}
}

var globalImage;
var hasCorrectedWidth = false;

// This method corrects the width of an image when editting the image in the CMS or viewing an image in the page
function correctWidth( image )
{
	globalImage = image;
	if( !hasCorrectedWidth )
	{
		hasCorrectedWidth = true;
		correctWidthDelayed();
	}
}

// This is the delayed function that repeats until the image is correct
function correctWidthDelayed()
{
	if (globalImage.scrollWidth < 353)
		globalImage.parentElement.style.styleFloat = "left";
	else
		globalImage.parentElement.style.styleFloat = "none";

	if ( document.readyState == "complete" )
	{
		if( globalImage.scrollWidth > 535 )
		{
			globalImage.style.width = 515;
		}
	}
	else
		setTimeout( 'correctWidthDelayed()', 100);
}


// rekenmodule popup mousehover

/***********************************************
* Freejavascriptkit.com
* Visit http://www.freejavascriptkit.com for more free Javascripts source code
***********************************************/

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""


function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip
