//Global var to remember the onload Functions
var onloadFunctions = Array();

/**
 * Onload function Load all functions stored in onloadFunctions
 */
function doOnload()
{
	for(var myIndex = 0; myIndex < onloadFunctions.length; myIndex++ )
	{
		if(onloadFunctions[myIndex])
		{
			onloadFunctions[myIndex]( );
		}
	}
}


/**
 * Store a function to run in window.Onload
 */
window.addOnloadFunction = function(sName)
{
	iElement = onloadFunctions.length + 1;
	onloadFunctions[iElement] = sName;
}


 /**
  * Function to show popup with info what remembering your password means
  */
 function showWhyRememberPass()
 {
 	$('popup_window_content').update('Onthouden is voor mensen soms een lastige zaak. 1 klik met de muis en u hoeft nooit meer uw wachtwoord in te vullen...');
 	$('popup_okButton').style.display = 'block';
 	showPopup();
 }


 /**
  * Function to show popup with info how to enlarge the page
  */

 function showHowtoEnlarge()
 {
 	$('popup_window_content').update('U kunt de lettergrootte van de pagina vergroten en verkleinen door de Ctrl toets ingedrukt te houden, terwijl u met het scrollwiel van de muis schuift om in of uit te zoomen. Daarnaast kunt u ook met behulp van het toetsenbord de lettergrootte van de pagina bewerken door gelijktijdig de Ctrl toets en de &#45; of &#43; toets ingedrukt te houden');
 	$('popup_window_content').style.fontWeight = 'bold';
 	$('popup_window_content').style.fontSize = '16px';
 	$('popup_okButton').style.display = 'block';
 	showPopup();
 }

  /**
   * Function to show Webtv in popup
   */

  function showWebTV()
  {
  	$('popup_window_content').update('<embed width="380" height="240" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" flashvars="client_id=201&media_id=80917&start=0" name="QuadiaPlayer" bgcolor="#000000" salign="b" wmode="transparent" quality="high" src="http://static.quadiatv.com/player/2009312-Zig/player.swf"></embed>');
  	showPopup();
  }

  function showWebTVoptiemodel()
  {
  	$('popup_window_content').update('<embed width="380" height="240" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" flashvars="client_id=201&media_id=80917&start=30" name="QuadiaPlayer" bgcolor="#000000" salign="b" wmode="transparent" quality="high" src="http://static.quadiatv.com/player/2009312-Zig/player.swf"></embed>');
  	showPopup();
  }

  function showWebTVaanbodmodel()
  {
  	$('popup_window_content').update('<embed width="380" height="240" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" flashvars="client_id=201&media_id=80917&start=113" name="QuadiaPlayer" bgcolor="#000000" salign="b" wmode="transparent" quality="high" src="http://static.quadiatv.com/player/2009312-Zig/player.swf"></embed>');
  	showPopup();
  }

  function showWebTVlotingmodel()
  {
  	$('popup_window_content').update('<embed width="380" height="240" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" flashvars="client_id=201&media_id=80917&start=191" name="QuadiaPlayer" bgcolor="#000000" salign="b" wmode="transparent" quality="high" src="http://static.quadiatv.com/player/2009312-Zig/player.swf"></embed>');
  	showPopup();
  }

  function showWebTVdirectehuur()
  {
  	$('popup_window_content').update('<embed width="380" height="240" align="middle" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" flashvars="client_id=201&media_id=80917&start=214" name="QuadiaPlayer" bgcolor="#000000" salign="b" wmode="transparent" quality="high" src="http://static.quadiatv.com/player/2009312-Zig/player.swf"></embed>');
  	showPopup();
  }
 

 /**
  * Function change input type fields for Password
  */
function onFocusPassword()
{
	if($('loginfield_text').style.display != 'none')
	{
		$('loginfield_text').style.display = 'none';
		$('loginfield_pass').style.display = 'block';
		$('loginfield_pass').focus();
	}
}

function onBlurPassword()
{
	if($('loginfield_text').style.display == 'none' && $('loginfield_pass').value == '' )
	{
		$('loginfield_text').style.display = 'block';
		$('loginfield_pass').style.display = 'none';	
	}
}


/**
 * Function to add symbol seperator to ul
 */

function supernav_list ()
{
	oList = document.getElementById('supernav').getElementsByTagName('ul')[0];
	aListItems = oList.getElementsByTagName('li');
	
	for (var i=0;i<aListItems.length-1;i++)
	{
		var sHTML = aListItems[i].innerHTML;
		
		aListItems[i].innerHTML += ' &bull; ';
	}
	document.getElementById('zoekknop_super').value = '>';

}

function disclaimer_list ()
{
	oList = document.getElementById('disclaimer').getElementsByTagName('ul')[0];
	aListItems = oList.getElementsByTagName('li');
	
	for (var i=0;i<aListItems.length-1;i++)
	{
		var sHTML = aListItems[i].innerHTML;
		
		aListItems[i].innerHTML += ' &bull; ';
	}
}


/**
 * Show and Hide answers in de FAQ
 */
function showhideAnswer(element)
{
	var showhide = document.getElementById(element);

	if(showhide.style.display == 'none')
	{
		new Effect.BlindDown(element,{queue:'end'});
	}

	else

	{
		var showhide = document.getElementById(element);
		new Effect.BlindUp(element,{queue:'end'});
	}
}


/**
 * Show popup
 */
 function showPopup(bHideClose)
 {
	if(bHideClose)
	{
		$('closePopupButton').style.display = 'none';
	}	
	else
	{
		$('closePopupButton').style.display = 'block';
	}	
	 
 	window.setTimeout("adjustPosition()", 300);
 }

function hidePopup()
{
	new Effect.Fade('popup_window',{duration: '0.2'});
	setTimeout("Effect.Fade('popup_overlay',{duration: '0.4'})",400);
}

function setPopupContent( sHtml )
{
	for( i = 0; i < $('popup_window').childNodes.length; i++ )
	{
		if( $('popup_window').childNodes[i].className == 'popup_window_content' )
		{
			$('popup_window').childNodes[i].innerHTML = sHtml;
		}
	}
}

function showOkPopup( message, okFunction )
{
	//Create the ok button
	var okButton = document.createElement( 'input' );
	okButton.setAttribute( 'type', 'button' );
	okButton.className = 'ok';
	okButton.name = 'okButton';
	okButton.id = 'popup_okButton';
	okButton.value = 'Ok';
	
	//Create a text element and add text and buttons
	var pMessage = document.createElement( 'p' ); 
	pMessage.innerHTML = message;
	
	var htmlContent = document.createElement( 'p' );
	htmlContent.appendChild( pMessage );
	htmlContent.appendChild( okButton );
	
	setPopupContent( htmlContent.innerHTML );
	
	//Set onclick events for buttons
	$( 'popup_okButton' ).onclick = new Function( okFunction + '()' );

	showPopup(true);
	
	return;
}

function showYesNoPopup( message, yesFunction, noFunction )
{
	//Create two buttons
	var yesButton = document.createElement( 'input' );
	yesButton.setAttribute( 'type', 'button' );
	yesButton.className = 'yes';
	yesButton.name = 'yesButton';
	yesButton.id = 'popup_yesButton';
	yesButton.value = 'Ja';
	
	var noButton = document.createElement( 'input' );
	noButton.setAttribute( 'type', 'button' );
	noButton.className = 'no';
	noButton.name = 'noButton';
	noButton.id = 'popup_noButton';
	noButton.value = 'Nee';
	
	//Create a text element and add text and buttons
	var pMessage = document.createElement( 'p' ); 
	pMessage.innerHTML = message;
	
	var htmlContent = document.createElement( 'p' );
	htmlContent.appendChild( pMessage );
	htmlContent.appendChild( yesButton );
	htmlContent.appendChild( noButton );
	setPopupContent( htmlContent.innerHTML );
	
	//Set onclick events for buttons
	$( 'popup_yesButton' ).onclick = new Function( yesFunction + '()' );
	$( 'popup_noButton' ).onclick = new Function( noFunction + '()' );

	showPopup();
	
	return;
}

var iMarginTop;

function adjustPosition()
{
	$('popup').style.display ='block';

	var iHeight = $('popup_window').getHeight();
	var iWidth = $('popup_window').getWidth();

	$('popup_window').style.marginLeft = '-'+ iWidth / 2 + 'px';

	if(!iMarginTop && iMarginTop != 0)
	{	
		iMarginTop = parseInt($('popup_window').getStyle('margin-top').replace('px',''));
	}
	aScroll = getScrollSize();

	$('popup_window').style.marginTop = iMarginTop + aScroll[1] + 'px';
	
	$('popup').style.display ='none';

	$('popup').style.display = 'block';
	new Effect.Appear('popup_overlay',{	duration: '0.4', from: 0.0, to: 0.8});
	setTimeout("Effect.Appear('popup_window',{duration: '0.2'})",400);
}

function getScrollSize() 
{
	
	  var iScrollX = 0, iScrollY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) 
	  {
		  iScrollY = window.pageYOffset;
		  iScrollX = window.pageXOffset;
	  } 
	  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
	  {
		  iScrollY = document.body.scrollTop;
		  iScrollX = document.body.scrollLeft;
	  } 
	  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
	  {
		  iScrollY = document.documentElement.scrollTop;
		  iScrollX = document.documentElement.scrollLeft;
	  }
	  
	  return [ iScrollX, iScrollY ];
}

/**
 * Function for content buttons to have an action on them selve AND change content
 * 
 * var string holds the active id 
 */
var sActiveId;

/**
 * var string holds the active link element
 */
var sActiveLinkEl;

/**
 * shows an element, hides an active one
 */	
function showItems(sId, sEl)
{
	//if active element and active element is not the same as the required one, hide it!

	if(sId != sActiveId)
	{
		if ($(sId) == null)
		{
			return true;
		}
		else
		{
			$(sId).removeClassName('hidden');
		}

		if(sActiveId)
		{
			hideActive();
		}

		$(sId).style.display ='none';

		new Effect.Move('content_'+sEl, { queue: 'end', x: 174, y: 0, mode: 'relative', duration: .5 });
		new Effect.Appear(sId, { delay: .5, duration: 1.0 });
		
//		if(sActiveId != '')
//		{
//			//change the history uri on the homepage
//			History.softset('tabBtn', sEl);
//		}
		sActiveId 		= sId;
		sActiveLinkEl 	= sEl;
	}
}

function hideActive()
{
	$(sActiveId).addClassName('hidden');

	new Effect.Move('content_'+sActiveLinkEl, { queue: 'end', x: -174, y: 0, mode: 'relative', duration: .5 });

	sActiveId 		= null;
	sActiveLinkEl 	= null;
}

function postwith (to,p)
{
	var myForm = document.createElement('form');
	myForm.method='post';
	myForm.action = to;
	for (var k in p)
	{
		var myInput = document.createElement('input');
		myInput.setAttribute('name', k);
		myInput.setAttribute('value', p[k]);
		myForm.appendChild(myInput);
	}
	document.body.appendChild(myForm);
	myForm.submit();
	document.body.removeChild(myForm);
}


/**
 * Function for content buttons to change content
 * 
 * var string holds the active id 
 */
var sActiveContentId;

/**
 * shows an id, hides an active one
 */	
function showContent(sId)
{
	//if active element and active element is not the same as the required one, hide it!
	
	if(sId != sActiveContentId)
	{
		if ($(sId) == null)
		{
			return true;
		}
		else
		{
			$(sId).removeClassName('hidden');
		}

		if(sActiveContentId)
		{
			hideActiveContent();
		}

		$(sId).style.display ='block';
		
		sActiveContentId 		= sId;
	}
}

function hideActiveContent()
{
	$(sActiveContentId).addClassName('hidden');

	sActiveContentId 		= null;
}

/**
 * Big Map Search
 * 
 * Shows and hides highlighted area and content
 */
function big_original() 
{
	document.bigmapsearch.src = Imagex.src; return true; 
}

function showbig1() 
{
	new Effect.Appear('info_1',{duration: '0.08'});
}

function showbig2() 
{
	new Effect.Appear('info_2',{duration: '0.08'});
	document.bigmapsearch.src = Image2.src; return true;
}

function showbig3() 
{
	new Effect.Appear('info_3',{duration: '0.08'});
	document.bigmapsearch.src = Image3.src; return true;
}

function showbig4() 
{
	new Effect.Appear('info_4',{duration: '0.08'});
}

function showbig5() 
{
	new Effect.Appear('info_5',{duration: '0.08'});
	document.bigmapsearch.src = Image5.src; return true;
}

function showbig6() 
{
	new Effect.Appear('info_6',{duration: '0.08'});
	document.bigmapsearch.src = Image6.src; return true;
}

function showbig7() 
{
	new Effect.Appear('info_7',{duration: '0.08'});
	document.bigmapsearch.src = Image7.src; return true;
}

function showbig8() 
{
	new Effect.Appear('info_8',{duration: '0.08'});
}

function showbig9() 
{
	new Effect.Appear('info_9',{duration: '0.08'});
}

function showbig10() 
{
	new Effect.Appear('info_10',{duration: '0.08'});
	document.bigmapsearch.src = Image10.src; return true;
}

Imagex = new Image
Imagex.src = "/images/mapsearch_big_default.gif"

Image2 = new Image
Image2.src = "/images/mapsearch_big_tholen.gif" 

Image3 = new Image
Image3.src = "/images/mapsearch_big_steenbergen.gif" 

Image5 = new Image
Image5.src = "/images/mapsearch_big_ettenleur.gif" 

Image6 = new Image
Image6.src = "/images/mapsearch_big_bergenopzoom.gif"

Image7 = new Image
Image7.src = "/images/mapsearch_big_roosendaal.gif" 

Image10 = new Image
Image10.src = "/images/mapsearch_big_woensdrecht.gif" 


/**
 *  Hide info
 */
function hideInfo1() 
{
	new Effect.Fade('info_1',{duration: '0.04'});
}

function hideInfo2() 
{
	new Effect.Fade('info_2',{duration: '0.04'});
}

function hideInfo3() 
{
	new Effect.Fade('info_3',{duration: '0.04'});
}

function hideInfo4() 
{
	new Effect.Fade('info_4',{duration: '0.04'});
}

function hideInfo5() 
{
	new Effect.Fade('info_5',{duration: '0.04'});
}

function hideInfo6() 
{
	new Effect.Fade('info_6',{duration: '0.04'});
}

function hideInfo7() 
{
	new Effect.Fade('info_7',{duration: '0.04'});
}

function hideInfo8() 
{
	new Effect.Fade('info_8',{duration: '0.04'});
}

function hideInfo9() 
{
	new Effect.Fade('info_9',{duration: '0.04'});
}

function hideInfo10() 
{
	new Effect.Fade('info_10',{duration: '0.04'});
}


/**
 * Big Region Map
 * 
 * Shows and hides highlighted area and links
 */
function showLink(sId)
{
	$(sId).style.color ='#7cb61e';
	$(sId).style.textDecoration ='underline';
}

function hideLink(sId)
{
    $(sId).style.color ='#478996';
	$(sId).style.textDecoration ='none';
}

function bigregion_original() 
{
	document.bigregionmap.src = Imagex.src; return true; 
}

function showRegion1() 
{
}

function showRegion2() 
{
	document.bigregionmap.src = Image2.src; return true;
}

function showRegion3() 
{
	document.bigregionmap.src = Image3.src; return true;
}

function showRegion4() 
{
}

function showRegion5() 
{
	document.bigregionmap.src = Image5.src; return true;
}

function showRegion6() 
{
	document.bigregionmap.src = Image6.src; return true;
}

function showRegion7() 
{
	document.bigregionmap.src = Image7.src; return true;
}

function showRegion8() 
{
}

function showRegion9() 
{
}

function showRegion10() 
{
	document.bigregionmap.src = Image10.src; return true;
}

function getAdnumber()
{
	var sUrl = '/output/json/woningaanbod/aanbod/advertentie';
	
	new Ajax.Request(sUrl, {
        method: 'post',
		parameters: {
			adsearch: $('adsearchform').adsearch.value
        },
        onSuccess: function(transport, oJson){
        	if(oJson && oJson.id != 0)
			{
        		window.location.href = '/woningaanbod/aanbod/details/'+oJson.id;
			}
			else
			{
				$('adsearchform').adsearch.value = 'advertentienummer';
				
				$('popup_window_content').update(oJson.message);

				showPopup();
			}
		},
        onFailure: function(){
        	alert('Inloggen mislukt');
        }
    });
}
