/**
 * Include script for VVD Leiden website.
 * 
 * @author R.J.T. de Vries <rdevries@thirdwave.nl>
 * @version 1.00, 07/25/2007
 * @access public
 */
 
	//------------------------------------------------------------------------------
	// PHASE I: INCLUDE ALL NECESSARY JAVASCRIPT FILES.
	//------------------------------------------------------------------------------
	document.write("<script src='/cms/jscripts/cms.cookie.js'></script>");
	document.write("<script src='/cms/jscripts/cms.functions.js'></script>");
	document.write("<script src='/cms/jscripts/cms.event.js'></script>");
	document.write("<script src='/inc/jscripts/ddMenus.js'></script>");
	document.write("<script src='/inc/jscripts/ImagePopup.js'></script>");
	document.write("<script src='/inc/jscripts/ChangeImage.js'></script>");
	document.write("<script src='/inc/jscripts/cufon-yui.js' type='text/javascript'></script>");
	document.write("<script src='/inc/jscripts/fonts/AntiqueOlive_400-AntiqueOlive_700-AntiqueOlive_italic_400.font.js' type='text/javascript'></script>");
	
	//------------------------------------------------------------------------------
	// PHASE II: INITIALIZATION FUNCTION, CALLED ON WINDOW LOAD EVENT
	//------------------------------------------------------------------------------

	/**
	 * Instance of ddMenus object.
	 * @var object ddmenus
	 * @access global
	 */
	var ddmenus;

	/**
	 * Instance of ImagePopup object.
	 * @var object imagePopup
	 * @access global
	 */
	var imagePopup;
	
	/**
	 * Instance of Photoalbum object.
	 * @var object changeImage
	 * @access global
	 */
	var changeImage = false;
	
	/**
	 * Initialize website. Called from window.onload event.
	 *
	 * Starts with calling the ddinit() function which initializes the dropdown
	 * menus in the website. After that, the current document is checked for forms
	 * in which special events need to be attached to form elements. (such as a
	 * select element that needs an onchange event.) Finally, I.E. is instructed 
	 * not to keep a background-image cache, as that keeps I.E. from flickering on
	 * mouseover.
	 * 
	 * @author R.J.T. de Vries <rdevries@thirdwave.nl>
	 * @return 	void
	 * @access	public
	 */
	function init() {
		ddmenus = new ddMenus;
		if ( !ddmenus.init() ) {
			alert('Dropdown menus kunnen niet worden geactiveerd');
		}
		imagePopup = new ImagePopup();
		imagePopup.init();
		
		if ( isIE() ) {
			try {
				document.execCommand('BackgroundImageCache', false, true);
			} catch(err) {}
		}
		
		// Cufon.replace('.t ul li a,.groep, .campagneBanner a, .campagneSmall a, .campagneKop', { fontFamily: 'AntiqueOliveBlack',hover: true});
	} // init()

	/**
	 * Toggles the visibility of the Reaction form by resizing is to 1px (hidden)
	 * or full height (visible).
	 * 
	 * @return	void
	 */
	function toggleReactionform() {
		var reactformdiv = document.getElementById('reactformdiv');
		if ( typeof(reactformdiv) == 'undefined' || reactformdiv == 'null' ) return;
		if ( reactformdiv.style.visibility == 'visible' ) {
			reactformdiv.style.visibility = 'hidden';
			reactformdiv.style.height = '1px';
		} else {
			reactformdiv.style.visibility = 'visible';
			reactformdiv.style.height = '300px';
		}
	} // toggleReactionform()

	/**
	 * If given link points to nowhere, then return false.
	 * This function is called onclick for each menu-link in the main menu.
	 * 
	 * @author R.J.T. de Vries <rdevries@thirdwave.nl>
	 * @param 	object		obj		DOM object of link that fired the event.
	 * @return 	boolean					true if link is sensible, false if not.
	 */
	function checkLink(obj) {
		if ( !is_object(obj) ) return false;
		if ( obj.href.indexOf('objID=0') != -1 ) return false;
		return true;
	} // checkLink()
	
	/**
	 * Ask confirmation for delete action.
	 * 
	 * @return	boolean		true on confirmation, false on cancel.
	 */
	function confirmIt() {
		if ( confirm("Weet u zeker dat u wilt verwijderen?") ) {
			return true;
		}
		return false;
	}	// confirmIt()

	window.onload = init;
	
	/**
	 * Set the display property of the form-part 'delivery address' to either
	 * block or none.
	 * 
	 * @param		boolean		visible		true to show, false to hide.
	 * @return	void;
	 */
	function toggleDeliveryAddress(visible) {
		var tbody = document.getElementById('delivery_address');
		if ( !is_object(tbody) ) return false;
		tbody.style.display = visible ? 'block' : 'none';
	} // toggleDeliveryAddress()

	/**
	 * Submit the form on this page and set the hidden form-variable 'step' to
	 * either one step back or one step forward.
	 * 
	 * @author R.J.T. de Vries <rdevries@thirdwave.nl>
	 * @param		object		obj		object that invoked the call to this function.	
	 * @param		integer 	incr 	the number to increment 'step' with (1/-1)
	 * @access	public
	 */
	function take_step(obj, incr) {
		var original_step = document.getElementById('original_step').value;
		
		// get first parent that is first form.
		while ( obj.tagName.toUpperCase() != 'FORM' && is_object(obj.parentNode) ) {
			obj = obj.parentNode;
		} // while()
		
		obj.step.value = parseInt(original_step) + incr;
		if ( incr < 1 ) obj.action = 'memberpage.html';
		else if ( !checkFields(obj) ) return false;

		var nextbtn = document.getElementById('next');
		if ( is_object(nextbtn) ) nextbtn.disabled = true;

		obj.submit();
		return false;
	} // take_step()	