// Do some stuff on load
window.onload = function () 
{
	// Break out of frames
	if ( top.location != location ) 
	{
		top.location.href = document.location.href;
	}

	// Focus on first element of first form 
	if ( document.forms[0] )
	{
		document.forms[0].elements[0].focus();
	}
	
	if ( document.getElementById ) 
	{
		// Alert if notice is present
		if ( document.getElementById('notice') ) 
		{
			document.getElementById('notice').style.display = 'none';   
			alert(document.getElementById('notice').innerHTML);
		}
		
		// Automatic stuff for the address page
		if ( location.href.toLowerCase().indexOf('adresse.php') >= 0 ) 
		{
			if ( document.getElementById('phone') )
			{
				phone = document.getElementById('phone');
				phone.onchange = function ()
				{
 					if ( /^\d{4}$/.exec(phone.value) )
					{
						phone.value = '8942' + phone.value;
					}
				}
			}
			if ( document.getElementById('email') )
			{
				email = document.getElementById('email');
				email.onchange = function ()
				{
					if ( ( email.value != '' ) && ( email.value.indexOf('@') == -1 ) )
					{
						email.value = email.value + "@biology.au.dk"
					}
				}
			}
		}
		
		// Test
		document.getElementById('footer-address').style.bottom = '0px';
		document.getElementById('footer-address').style.bottom = '15px';
		document.getElementById('contents').style.padding = '0px 0px 50px 0px';
	}
	
	// Issue warning when deleting
	if ( document.images ) 
	{
		len = document.images.length;
		for (i = 0; i < len; i++) 
		{
			image = document.images[i]
			
			// Archive
			if ( image.id.indexOf('arkiv.') == 0 ) 
			{
				image.onclick = function ()
				{
					return confirm('Du er ved at slette ' + this.title + '. Vil du fortsætte?');
				}
			}
			
			// Courses
			if ( image.id.indexOf('undervisning.') == 0 )
			{
				image.onclick = function ()
				{
					return confirm('Du er ved at slette ' + this.title + '. Vil du fortsætte?');
				}
			}
			
			// Users
			if ( image.id.indexOf('brugere.') == 0 )
			{
				image.onclick = function ()
				{
					return confirm('Du er ved at slette ' + this.title + '. Vil du fortsætte?');
				}
			}
			
			// Calendar
			if ( image.id.indexOf('kalender.') == 0 )
			{
				image.onclick = function ()
				{
					return confirm('Du er ved at slette ' + this.title + '. Vil du fortsætte?');
				}
			}
			
			// Temporary use of loop
			if ( image.id.indexOf('stilling.') == 0 )
			{
				image.onclick = function ()
				{
					return confirm('Du er ved at slette stilingsbetegnelsen ' + this.title + '. Vil du fortsætte?');
				}
			}
			
			// Misuse for loop to add titles to images
			if ( !image.title && image.alt )
			{
				image.title = image.alt;
			}
		}
	}
}
 
function testmig()
{
	alert('testmig');
}

// Pop up a new window
function popup(url, width, height)
{
	top_space = (screen.height - height) / 2;
	side_space = (screen.width - width) / 2;
	popupWin = window.open(url, 'popupWin', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width='+width+', height='+height+', top='+top_space+', left='+side_space);
}

// Toggle visibility of elements
function toggleVisibility(id)
{
	if ( document.getElementById )
	{
		if ( document.getElementById(id) )
		{
			element = document.getElementById(id);
			if ( element.style.display == 'none' )
			{
				element.style.display = 'block';
			}
			else
			{
				element.style.display = 'none';
			}
		}
	}
}