/*
Javascript for www.identiteitenbranding.nl

Written by Meinaart van Straalen - Zicht nieuwe media ontwerpers bv (c) 2004
*/

var UP = 1;
var DOWN = 2;

/*
	This function changes the style.display property of an element to "none".
	The function arguments are a list of ID's (ie: hide( 'element1', 'element2' );
*/
function hide() {
	if( !document.getElementById ) return;
	var args = hide.arguments;
	for( var i=0; i < args.length; i++ ) {
		document.getElementById( args[i] ).style.display = "none";
	}
}

/*
	This function checks whether a string contains a valid e-mailaddress or not.
*/
function isValidEmail( email ) {
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(email);
}

/*
	This function moves an <OPTION> HTMLelement up or down in a <SELECT>-box.
	
	Optional: 
	if the argument orderField is specified the values of the oSelect-box
	will be written in that field seperated by a ; (semicolon).
*/
function moveOption( oSelect, direction, orderField ) {
	if( oSelect.selectedIndex != -1 ) {
		if( direction == UP ) {
			var newIndex = oSelect.selectedIndex - 1;
		} else {
			var newIndex = oSelect.selectedIndex + 1;		
		}
		
		if( newIndex < 0 ) newIndex = 0;
		else if ( newIndex > ( oSelect.options.length - 1 ) ) newIndex = oSelect.options.length - 1;
		
		var oldIndex = oSelect.selectedIndex;
		
//		oSelect.options[ oSelect.selectedIndex ].swapNode( oSelect.options[ newIndex ] );

		if( direction == UP && oldIndex > 0 ) {
			var tmp = new Array(oSelect.options[newIndex].text,oSelect.options[newIndex].value);

			oSelect.options[newIndex].text = oSelect.options[oldIndex].text;
			oSelect.options[newIndex].value = oSelect.options[oldIndex].value;

			oSelect.options[oldIndex].text = tmp[0];
			oSelect.options[oldIndex].value = tmp[1];

			oSelect.options[newIndex].selected = true;
		} else if ( direction == DOWN  && newIndex < oSelect.options.length ) {
			var tmp = new Array(oSelect.options[newIndex].text,oSelect.options[newIndex].value);

			oSelect.options[newIndex].text = oSelect.options[oldIndex].text;
			oSelect.options[newIndex].value = oSelect.options[oldIndex].value;
	
			oSelect.options[oldIndex].text = tmp[0];
			oSelect.options[oldIndex].value = tmp[1];

			oSelect.options[newIndex].selected = true;
		}
			
		if( typeof orderField != "undefined" ) {
			orderField.value = "";
			for( var i=0; i < oSelect.options.length; i++ ) {
				orderField.value += oSelect.options[i].value + ";";
			}
		}
	}
}

function openBegrippen( begrip ) {
	var begrippenWindow = window.open( 'begrippen.html#' + begrip, 'begrippenWindow', 'width=520,height=394,scrollbars=yes,toolbar=no,history=no,status=no,statusbar=no' );
	begrippenWindow.focus();
}

function openReaction( nav_id ) {
	void(0);
}

function openTools( begrip ) {
	var toolsWindow = window.open( 'tools.html#' + begrip, 'toolsWindow', 'width=520,height=400,scrollbars=yes,toolbar=no,history=no,status=no,statusbar=no' );
	toolsWindow.focus();
}

function openNieuws( nieuwsbrief, item ) {
	var newsWindow = window.open( './nieuwsbrief/' + nieuwsbrief + '.html#' + item, 'newsWindow', 'width=780,height=600,scrollbars=yes,toolbar=no,history=no,status=no,statusbar=no' );
	newsWindow.focus();
}

function nieuwsOpener( url ) {
	if(window.opener && !window.opener.closed) {
		window.opener.location.href = url;
		self.close();
		window.opener.focus();
	} else {
		window.open(url);
		self.close();
	}
}

/*
	This function changes the style.display property of an element to "block".
	The function arguments are a list of ID's (ie: show( 'element1', 'element2' );
*/
function show() {
	if( !document.getElementById ) return;
	var args = show.arguments;
	for( var i=0; i < args.length; i++ ) {
		document.getElementById( args[i] ).style.display = "block";
	}
}
