/**
 * file contains all specifix wooniezie functions
 *
 */

/**
 * create navigation via javasccript
 * 
 * @param string
 *            sNavContainerId id of div to place navigation in
 * @param string
 *            sPageContainerPrefix the prefix of id of the element that contains
 *            a page
 * @param integer
 *            iAmountOfPages
 * @param integer
 *            iActivePage
 * 
 * F.E. html will look like
 * 
 * <div id="page-1"> pagina 1 </div> <div id="page-2"> pagina 2 </div> <div
 * id="page-3"> pagina 3 </div>
 * 
 * <div id="navigation"></div>
 * 
 * createNavigation('navigation','page-',3,1);
 */
function createNavigation(sNavContainerId, sPageContainerPrefix,iAmountOfPages,iActivePage)
{

	var sUl = '<ul>';
	
	//create link for `prev`
	sUl += '<li>';
	
	if(iActivePage != 1)
	{
		sUl += '<a href="#" onclick="createNavigation(\''+sNavContainerId+'\',\''+sPageContainerPrefix+'\','+iAmountOfPages+','+ (iActivePage - 1) +'); return false;">';
	}
	
	sUl += '&lt;';
	
	if(iActivePage != 1)
	{
		sUl += '</a>';
	}
	
	sUl += '</li>';
	
	//create the pages
	for(iCounter = 1; iCounter<=iAmountOfPages;iCounter++)
	{
		sClass = 'inactive';
		
		// hide/show the pages
		if(iActivePage == iCounter)
		{
			sClass = 'active';
			$(sPageContainerPrefix + (iCounter)).show();
		}
		else
		{
			$(sPageContainerPrefix + (iCounter)).hide();
		}
		
		//create link to page
		sUl += '<li class="'+sClass+'">';
		sUl += '<a href="#" onclick="createNavigation(\''+sNavContainerId+'\',\''+sPageContainerPrefix+'\','+iAmountOfPages+','+iCounter+'); return false;">'+iCounter+'</a>';
		sUl += '</li>';
	}
	
	//create link for `next`
	sUl += '<li>';
	
	if(iActivePage < iAmountOfPages)
	{
		sUl += '<a href="#" onclick="createNavigation(\''+sNavContainerId+'\',\''+sPageContainerPrefix+'\','+iAmountOfPages+','+ (iActivePage + 1) +'); return false;">';
	}
	sUl += '&gt;';
	
	if(iActivePage < iAmountOfPages)
	{
		sUl += '</a>';
	}
	
	sUl += '</li>';
	
	sUl += '</ul>';

	$(sNavContainerId).innerHTML = sUl;
}


var activeFAQAnswer;
function showFAQ(answer)
{
	if(activeFAQAnswer)
	{
		$(activeFAQAnswer).style.display = 'none';
		$('bullet_'+ activeFAQAnswer).src = '/images/faqQuestion_unselected.png';
		$('link_'+ activeFAQAnswer).setAttribute('style', 'color:#25546E !important');
		$('question_' + activeFAQAnswer).style.background = 'none';
		$('close_' + activeFAQAnswer).style.display = 'none';
	}
	if(answer != 'none')
	{
		activeFAQAnswer = answer;
		
		$(answer).style.display = 'block';
		$('bullet_'+ answer).src = '/images/faqQuestion_selected.png';
		$('link_'+ activeFAQAnswer).setAttribute('style', 'color:#FFF !important');
		$('question_' + activeFAQAnswer).style.backgroundColor = '#91acbd';
		$('close_' + activeFAQAnswer).style.display = 'block';
	}
	else
		activeFAQAnswer = null;
	return false;
}

function setSize() {
	  var myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myHeight = document.body.clientHeight;
	  }
	  if($('content_container'))
		  $('content_container').style.minHeight = (myHeight-395) + "px";

	  if($('container_rightbar_right') != null)
	  {
		  crr = $('container_rightbar_right');
		  crr.style.minHeight = $('content_container').offsetHeight-20 + "px";
	  }
}


var hometab_CurrentlyOpen;

function moveHomeTab(element)
{	
	// Set Default
	if(hometab_CurrentlyOpen == null)
	{
		hometab_CurrentlyOpen = 'tab1';
	}
	if(element == hometab_CurrentlyOpen)
		return false;
	$('tab_protector').style.display = 'block';
	// Fade the labels
	new Effect.Fade(hometab_CurrentlyOpen + '_label_image_active', {duration:0.8, from: 1.0, to: 0.0});
	new Effect.Appear(hometab_CurrentlyOpen + '_label_image', {duration:0.8});
	
	new Effect.Appear(element + '_label_image_active', {duration:1.0});
	new Effect.Fade(element + '_label_image', {duration:1.0, from: 1.0, to: 0.0});
	
	// Move div's till active div is shown
	
	$(hometab_CurrentlyOpen + "_label").addClassName('pointer');
	if(hometab_CurrentlyOpen == 'tab1')
	{
		if(element == 'tab2')
		{
			hometab_CurrentlyOpen = element;
			doMove(element, -700, 0);
		}
		if(element == 'tab3')
		{
			hometab_CurrentlyOpen = element;
			doMove('tab2', -700, 0);
			doMove(element, -700, 0);
		}
	}
	
	if(hometab_CurrentlyOpen == 'tab2')
	{
		if(element == 'tab1')
		{
			hometab_CurrentlyOpen = element;
			doMove('tab2', 700, 0);
		}
		if(element == 'tab3')
		{
			hometab_CurrentlyOpen = element;
			doMove(element, -700, 0);
		}
	}
	
	else if(hometab_CurrentlyOpen == 'tab3')
	{
		if(element == 'tab1')
		{
			hometab_CurrentlyOpen = element;
			doMove('tab3', 700, 0);
			doMove('tab2', 700, 0);
			
		}	
		if(element == 'tab2')
		{
			hometab_CurrentlyOpen = element;
			doMove('tab3', 700, 0);
		}
	}
	$(hometab_CurrentlyOpen + "_label").removeClassName('pointer');
	setTimeout("$('tab_protector').style.display = 'none';", 1000);
	return false;	
}

function doMove(element, v_x, v_y)
{
	new Effect.Move(element, { x: v_x, y: v_y, delay: 0, duration: 1 });
	
}

function externalLinks() 
{
	 if (!document.getElementsByTagName) 
		 return;
	 var anchors = document.getElementsByTagName("a");
	 for (var i=0; i<anchors.length; i++) 
	 {
		 var anchor = anchors[i];
		 if (anchor.getAttribute("rel") == "external")
		 {
			 anchor.target = "_blank";
		 }
	 }
}

/**
 * Image Rollover
 * Docu. wiki.zig
 */

function imageMap(sAreaMap,sMap,aAreaSrc, bDebug)
{
	var oMap 	= document.getElementById(sMap);
	var sOldSrc = oMap.src;
	var aArea = $(sAreaMap).getElementsByTagName('area');
	var iLength = aArea.length;
	
	for(var iCounter = 0; iCounter < iLength; iCounter++)
	{
		var oArea = aArea[iCounter];		
		var sKey = oArea.alt.toLowerCase();
		if(aAreaSrc[sKey])
		{
			oArea.onmouseover 	= function(){oMap.src = aAreaSrc[this.alt.toLowerCase()];}
			oArea.onmouseout 	= function(){oMap.src = sOldSrc;}
		}
		else
		{
			if(bDebug)
			{
				alert('No rollover image defined for ' + sKey);
			}
		}
	}
}

function imageMapLink(sAreaMap,sMap,aAreaSrc, bDebug)
{
	var oMap 		= document.getElementById(sMap);
	var sOldSrc 	= oMap.src;
	var aList		= document.getElementsByName('area_link');
	var iListlength = aList.length;
	
	for(var iCounter = 0; iCounter < iListlength; iCounter++)
	{
		var oLink = aList[iCounter];		
		var sKey = oLink.id.toLowerCase();

		if($(sKey))
		{
			oLink.onmouseover 	= function(){oMap.src = aAreaSrc[this.id.toLowerCase()];}
			oLink.onmouseout 	= function(){oMap.src = sOldSrc;}
		}
	}
}

function confirmDelete(sUrl,sMessage)
{
	if(!sMessage)
	{
		sMessage = 'Weet u het zeker?';
	}

	Popup.open({content				: sMessage,
				showConfirmSuccess	: true,
				showConfirmCancel	: true,
				textConfirmSucces	: 'Ja',
				textConfirmCancel	: 'Nee',
				onConfirmSuccess	: function(){document.location = sUrl;return false;}
				});
}

/**
 * Change Graybox tab
 */

function changeInternalTab(tabid)
{
	
	// Get the active tab
	var parent = $(tabid).parentNode.parentNode;
	var active = null;
	for(li in parent.childNodes)
	{
		if(parent.childNodes[li].className == 'active')
		{
			active = parent.childNodes[li];
			
			// Make active tab inactive
			$(active.id).removeClassName('active');
			
			// Make active content invisble
			$(active.id + '_container').style.display = 'none';
		}
	}
	
	// Make selected tab active
	$($(tabid).parentNode.id).addClassName('active');
	
	// Make selected content visible
	$($(tabid).parentNode.id + '_container').style.display = 'block';
}

active = null;
function changeTab(tabid)
{
	// Get the active tab
	if($(tabid))
	{
		var parent = $(tabid).parentNode;
		for(li in parent.childNodes)
		{
			if(parent.childNodes[li].className == 'active')
			{
				active = parent.childNodes[li];
				// Make active tab inactive
				$(active.id).removeClassName('active');
			}
		}
		
		// Make selected tab active
		$(tabid).addClassName('active');
	}
}

/**
 * Show ID and hide other ID shown previous
 */

var sActiveId;

function showItem(sId)
{
	if(sId != sActiveId)
	{
		if ($(sId) == null)
		{
			return true;
		}
		else
		{
			$(sId).removeClassName('hidden');
		}

		if(sActiveId)
		{
			hideActive();
		}

		$(sId).removeClassName('hidden');

		sActiveId 		= sId;
	}
}

function hideActive()
{
	$(sActiveId).addClassName('hidden');

	sActiveId 		= null;
}


/**
 * extend registration
 *
 */
function extendRegistration(sUrl)
{
	var oOptions =
	{
		content: 'Wilt u uw inschrijving met een jaar verlengen?',
		showConfirmSuccess: true,
		showConfirmCancel: true,
		textConfirmSucces: 'Ja',
		textConfirmCancel: 'Nee',
		onConfirmSuccess: 	function()
							{
								Popup.open({url: sUrl + '?ppage=extend',
											showClose: false});

								return false;
							},
		onConfirmCancel: 	function()
							{
								Popup.open({content: 'Let op! Indien u de inschrijving niet verlengt, kunt u genomen opties en uw opgebouwde wachttijd verliezen. Weet uw zeker dat u uw inschrijving nu niet wilt verlengen?',
											showConfirmSuccess: true,
											showConfirmCancel: true,
											textConfirmSucces: 'Ja, ik weet het zeker',
											textConfirmCancel: 'Nee, ik wil toch verlengen',
											onConfirmSuccess: 	function()
																{
																	var oRequest= new Ajax.Request(sUrl + '?ppage=notextend');
																	Popup.close();
																	return false;
																},
											onConfirmCancel	: 	function()
																{
																	Popup.open({url: sUrl + '?ppage=extend',
																				showClose: false});
		
																	return false;
																},
											showClose: false});

								return false;
							},
		showClose: false
	};

	Popup.open(oOptions);
	
}

/**
 * Show Howto enlarge text in popup
 */
function enlargeInfo()
{
	var oInfo =
	{
			content: '<img src="/images/popupEnlargeInfo.png" alt="Uitleg over lettervergroting" />',
			showConfirmSuccess: true
	}

	Popup.open(oInfo);
}

/**
 * Show logout message
 */
function logoutInfo(sUrl)
{
	var oInfo =
	{
			content: 'U bent succesvol uitgelogd.',
			textConfirmSucces: 'Sluiten',
			onConfirmSuccess: 	function()
			{
				window.location.href = sUrl;
			},
			showConfirmSuccess: true,
			showClose: false
	}

	Popup.open(oInfo);
}

/**
 * Function to show Webtv in popup
 */

function showWebTVlotingmodel()
{
	var oMovie = 
	{
		content: '<embed width=\"480\" height=\"320\" align=\"middle\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" flashvars=\"client_id=211&media_id=82762&start=127\" name=\"QuadiaPlayer\" bgcolor=\"#000000\" salign=\"b\" wmode=\"transparent\" quality=\"high\" src=\"http://static.quadiatv.com/player/2009312-Zig/player.swf\"></embed>',
		textConfirmSucces: 'Sluiten',
		showConfirmSuccess: true
	}
	Popup.open(oMovie);
}

function showWebTVaanbodmodel()
{
	var oMovie = 
	{
		content: '<embed width=\"480\" height=\"320\" align=\"middle\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" flashvars=\"client_id=211&media_id=82762&start=99\" name=\"QuadiaPlayer\" bgcolor=\"#000000\" salign=\"b\" wmode=\"transparent\" quality=\"high\" src=\"http://static.quadiatv.com/player/2009312-Zig/player.swf\"></embed>',
		textConfirmSucces: 'Sluiten',
		showConfirmSuccess: true
	}
	Popup.open(oMovie);
}

function showWebTVdthmodel()
{
	var oMovie = 
	{
		content: '<embed width=\"480\" height=\"320\" align=\"middle\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" flashvars=\"client_id=211&media_id=82762&start=150\" name=\"QuadiaPlayer\" bgcolor=\"#000000\" salign=\"b\" wmode=\"transparent\" quality=\"high\" src=\"http://static.quadiatv.com/player/2009312-Zig/player.swf\"></embed>',
		textConfirmSucces: 'Sluiten',
		showConfirmSuccess: true
	}
	Popup.open(oMovie);
}

function showWebTVoptiemodel()
{
	var oMovie = 
	{
		content: '<embed width=\"480\" height=\"320\" align=\"middle\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" flashvars=\"client_id=211&media_id=82762&start=56\" name=\"QuadiaPlayer\" bgcolor=\"#000000\" salign=\"b\" wmode=\"transparent\" quality=\"high\" src=\"http://static.quadiatv.com/player/2009312-Zig/player.swf\"></embed>',
		textConfirmSucces: 'Sluiten',
		showConfirmSuccess: true
	}
	Popup.open(oMovie);
}

/**
 * Function to show the movie on the frontpage
 */
function showHomePageMovie()
{
	var oMovie = 
	{
		content: '<embed width=\"480\" height=\"320\" align=\"middle\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" flashvars=\"client_id=211&media_id=82762&\" name=\"QuadiaPlayer\" bgcolor=\"#000000\" salign=\"b\" wmode=\"transparent\" quality=\"high\" src=\"http://static.quadiatv.com/player/2009312-Zig/player.swf\"></embed>',
		textConfirmSucces: 'Sluiten',
		showConfirmSuccess: true
	}
	Popup.open(oMovie);
}