$( document ).ready( function(){

	// Listen after a form sendMail submit
	$( 'form[name="sendMail"]' ).submit( function( e ){

		// Detach the form
		e.preventDefault();

		// Make ajaxCall to get result from sendMail
		$.post( 'http://www.brugerforening.dk/admin/mail.asp', $( 'form[name="sendMail"]' ).serialize(), function( data ){
			$( '#contactReturn' ).html( data );
		});
		//alert( $( 'form[name="sendMail"]' ).serialize() );

	});

	// Listen after a form login submit
	$( 'form[name="login"]' ).submit( function( e ){

		// Detach the form
		e.preventDefault();

		// Get username and password from form
		var sUsername = $( '#username' ).val();
		var sPassword = $( '#password' ).val();

		// Make ajaxCall to try to log in
		$.get( 'http://www.brugerforening.dk/admin/login.asp', {username: sUsername, password: sPassword }, function( data ){
			if ( data == '0' ){
				window.location.replace( 'http://www.brugerforening.dk/' );
			} else {
				$('#loginMessage').html( data + '<br />Du har ikke adgang til administrationen!' );
			}
		});

	});

	// Bind clickEvent to adminLinks
	$( '.adminE' ).click( function( e ){

		// Detach the link
		e.preventDefault();

		// Open popupwindow with url from link
		var sUrl = $( '.adminE' ).attr( 'href' );
		window.open( sUrl, 'admin', 'directories=0,fullscreen=0,height=650,width=600,menubar=0,scrollbars=1,resizable=0,status=0,title=0,toolbar=0');
		
	});

	// Bind clickEvent to adminLinks
	$( '.adminM' ).click( function( e ){

		// Detach the link
		e.preventDefault();

		// open popupwindow with url from link
		var sUrl = $( '.adminM' ).attr( 'href' );
		window.open( sUrl, 'admin', 'directories=0,fullscreen=0,height=450,width=600,menubar=0,scrollbars=1,resizable=0,status=0,title=0,toolbar=0' );

	});

});
