// 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;
	}
}

function gotoNewsLetterSubscription(strURL, strControlID)
{
	var strEmailadres = document.getElementById(strControlID).value;
	if(isValidEmail(strEmailadres)){
		window.location.href(strURL + '?subcriptionNieuwsbriefEmailadres=' + strEmailadres);
	}
	else{
		alert ('Vul svp een geldig emailadres in')
	}
}

function isValidEmail(str) {
	var patt=/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9]))+$/
	
	if (patt.exec(str)==null||patt.exec(str)=="")
	{
		return false
	}
	else
	{
		return true
	}
}

//function isValidEmail(str) {
//	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
//}



// 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 ); 
} 

// Create an array to hold the FAQ properties.
var questionArray = MultiDimensionalArray(10,8);

// This method adds an FAQ item to the array with all its properties. This must be done in preperation to using the FAQ
function addToFaqArray( answerDiv, topHRDiv, bottomHRDiv, backgroundDiv, listItem, anchor, isTop, isBottom )
{
	// Loop through the array
	for( i = 0; i < 10; i++ )
	{
		// Check for the first available empty space and add the properties
		if( questionArray[i][0] == '' )
		{
			questionArray[i][0] = answerDiv;
			questionArray[i][1] = topHRDiv;
			questionArray[i][2] = bottomHRDiv;
			questionArray[i][3] = backgroundDiv;
			questionArray[i][4] = listItem;
			questionArray[i][5] = anchor;
			questionArray[i][6] = isTop;
			questionArray[i][7] = isBottom;
			break;
		}
	}
} 

// This method toggles alle the questions off and then displays only the one that was clicked
// If you click the open item, it will close
function toggleQuestion( answerDiv, topHRDiv, bottomHRDiv, backgroundDiv, listItem, anchor, isTop, isBottom )
{
	var visible = '';
	var invisible = 'none';
	
	var topRuler	= document.getElementById('faqTopRuler');
	var bottomRuler = document.getElementById('faqBottomRuler');
	
	// Save the original open state to see if we are closing the open item
	var originalState = listItem.className;
	
	// Close all the open items
	for( i = 0; i < 10; i++ )
	{
		questionArray[i][0].style.display		= 'none';
		questionArray[i][1].style.display		= 'none';
		questionArray[i][2].style.display		= 'none';
		questionArray[i][3].className			= 'FAQListclosed';	
		questionArray[i][4].className			= 'closed';
		questionArray[i][5].style.fontWeight	= 'normal';
	}
	
	// Check if we are closing the open item
	if( originalState != 'open' )
	{
		answerDiv.style.display			= '';
		topHRDiv.style.display			= '';
		bottomHRDiv.style.display		= '';
		backgroundDiv.className			= 'FAQListopen';
		listItem.className				= 'open';
		anchor.style.fontWeight			= 'bold';
	}
	
	// Check if we have clicked the top item and if so, hide the top divider for better looks
	if ( isTop && originalState == 'open' )
		topRuler.style.display = '';
	else if ( isTop && originalState != 'open' )
		topRuler.style.display = 'none';
	else
		topRuler.style.display = '';

	// Check if we have clicked the bottom item and if so, hide the bottom divider for better looks
	if ( isBottom && originalState == 'open' )
		bottomRuler.style.display = '';
	else if ( isBottom && originalState != 'open' )
		bottomRuler.style.display = 'none';
	else
		bottomRuler.style.display = '';
}

// 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.
		objToResize.height = innerDoc.body.scrollHeight + 5;
	}
	catch( e ) 
	{
		window.status = e.message;
     
		// IE only, usefull only when cross-site scripting
		targetHeight = frame.document.body.scrollHeight;
		frame.style.height = targetHeight.toString() + "px";
	}
}

// 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);
}