browser = navigator.userAgent.toLowerCase();

if( browser.toLowerCase().indexOf( 'msie 6.0' ) != -1 )
	ie = true;
else
	ie = false;

if (ie) {
	if(document.referrer.match(/http:\/\/(?:www\.)?feierblumm\.com.*/i) == null && document.location.href.indexOf('page=browsers') == -1) {
		if (confirm("You are using an outdated version of Internet Explorer.\n"
				+ "In order to be able to view and use this page as intended, Internet Explorer 7 or newer is required.\n\n"
				+ "Click OK for more information or Cancel to continue anyway."))
			document.location.href = "?page=browsers";
	}
}

function IE_PNG24Hack() {
	if( !ie )
		return;
	var images = document.getElementsByTagName( 'img' );
	var i;
	for( i = 0; i < images.length; i++ )
		CheckImage( images[ i ] );
}

function CheckImage( image ) {
	if( !ie )
		return;
	var dummySrc = 'images/void.png';
	
	if( image.className.indexOf( 'png24' ) != -1 ) {
		image.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader( src='"
			+image.src+"', sizingMethod='image');";
		image.originalSrc = image.src;
		image.src = dummySrc;
	}
}

function HoverButtons() {
	var images = document.getElementsByTagName( 'img' );
	var i;
	for( i = 0; i < images.length; i++ ) {
		if( images[ i ].className.indexOf( 'imgbutton' ) == -1 )
			continue;
		
		var pos = images[ i ].src.lastIndexOf( '.' );
		if( pos == -1 )
			return;

		images[ i ].filename = images[ i ].src.substring( 0, pos );
		images[ i ].fileext = images[ i ].src.substring( pos );
		images[ i ].onmouseover = HoverImage;
		images[ i ].onmouseout = UnHoverImage;
		
		var preloadedImage = new Image();
		preloadedImage.src = images[ i ].filename + '-hover' + images[ i ].fileext;
	}
}


function ShowHide( item, flag ) {
	if( typeof item == 'string' )
		item = document.getElementById( item );
	if( flag )
		item.style.display = 'block';
	else
		item.style.display = 'none';
}

function ToggleVisible(item) {
	if (typeof item == 'string')
		item = document.getElementById(item);
	
	if (item.style.display == 'none' || item.style.display == '')
		item.style.display = 'block';
	else
		item.style.display = 'none';
}

function Show( item ) {
	ShowHide( item, true );
}

function Hide( item ) {
	ShowHide( item, false );
}


function HoverImage() {
	this.src = this.filename + '-hover' + this.fileext;
	CheckImage( this );
}

function UnHoverImage() {
	if( this.unhover == 0 )
		return;
	this.src = this.filename + this.fileext;
	CheckImage( this );
}

function IsVisible( element ) {
	if( typeof element == 'string' )
		element = document.getElementById( element );
	var s = getStyle( element, 'display' );
	return !( s == 'none' );
}


function ContainsClass( element, classs ) {
	if( element == undefined )
		return;
	if( typeof element == 'string' )
		element = document.getElementById( element );
		
	var classString = ' '+element.className+' ';
	return( classString.indexOf( ' '+classs+' ' ) != -1 );
}

function getElementsByClassName( className ) {
	if( document.getElementsByClassName )
		return document.getElementsByClassName( className );
	else {
		var result = new Array();
		var all;
		if( document.all )
			all = document.all;
		else
			all = document.getElementsByTagName( '*' );
		
		for( var i = 0; i < all.length; i++ ) {
			if( ContainsClass( all[ i ], className ) )
				result.push( all[ i ] );
		}
		
		return result;
	}
}

function getStyle(x,styleProp)
{
	if( typeof x == 'string' )
		x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

var lastItem;
function ShowGroupItem( item, groupName ) {
	if( typeof item == 'string' )
		item = document.getElementById( item );
	lastItem = item;
		
	var groupItems = getElementsByClassName( groupName );
	var showMainItem;

	for( var i = 0; i < groupItems.length; i++ ) {
		var show = false;
		var visibility = IsVisible( groupItems[ i ] );

		if( groupItems[ i ] == item && !visibility ) {
			showMainItem = true;
			continue;
		}
			
		ShowHide( groupItems[ i ], show );
	}
	
	if( showMainItem )
		Show( item );
}

function ShowElementSmooth( item, show) {
	return ShowHide( item, show );
}

var lastMigratedImage = undefined;
function MigrateImage( sourceId, destinationId ) {
	var source = document.getElementById( sourceId );
	var destination = document.getElementById( destinationId );

	var s;
	if( source.originalSrc )
		s = source.originalSrc;
	else
		s = source.src;
	destination.src = s;
	if( !IsVisible( destination ) )
		ShowElementSmooth( destination, true, 1.0, undefined, 'in' );
}

function SplitViewDisplay(id, prefix) {
	var item = ShowGroupItem(prefix + id, 'group');
	var show = IsVisible(lastItem);
	ShowHide(prefix + 'current', show);
	MigrateImage('image_' + id, 'image_current');
} 

function ShowLinks(id, prefix) {
	var item = ShowGroupItem( prefix+id, prefix + 'group' );
	var show = true;
	show = IsVisible( lastItem );
	ShowHide(prefix + 'current', show );
	MigrateImage( 'image_'+id, 'image_current' );
}

function GetInvolvedTopLink(show_id) {
	var ids = new Array('get-in-touch', 'membership', 'realize-your-project', 'donation');
	for (var i = 0; i < ids.length; i++) {
		if (ids[i] != show_id)
			document.getElementById(ids[i]).style.display = 'none';
	}
	document.getElementById(show_id).style.display = 'block';
}

function trim(str) {
	return str.replace(/^\s+/, '').replace(/\s+$/, '');
}

function validate_string(str) {
	if (str == undefined)
		return false;
	str = trim(str);
	return (str.length != 0)
}

function validate_number(num) {
	return (num != undefined && !isNaN(parseInt(num, 10)));
}

function validate_email(email) {
	if (!validate_string(email))
		return false;
	email = trim(email);
	return email.match(/^\S+@\S+\.\S+$/);
}

function GetInvolved_SubmitMemberForm(form) {
	var errors = new Array();
	if (!validate_string(form.firstname.value))
		errors.push("First name missing");
	if (!validate_string(form.lastname.value))
		errors.push("Last name missing");
	if (!validate_email(form.email.value))
		errors.push("Invalid e-mail address");
	if (form.email.value != form.email_verification.value)
		errors.push("E-Mail address verification failed: addresses do not match");
	if (!validate_string(form.address.value))
		errors.push("Address missing");
	if (!validate_number(form.postalcode.value))
		errors.push("Invalid postal code");
	if (!validate_string(form.city.value))
		errors.push("City missing");
	if (!validate_string(form.country.value))
		errors.push("Country missing");
	if (!validate_string(form.nationality.value))
		errors.push("Nationality missing");
	if (!validate_number(form.fee.value))
		errors.push("Invalid subscription fee entered");
	if (parseInt(form.fee.value) < 5)
		errors.push("Invalid subscription fee amount entered");
	
	if (errors.length != 0) {
		var errorStr = "Errors in form detected:\n\n" + errors.join("\n");
		alert(errorStr);
		return false;
	}
	
	return true;
}











