function addLoadEvent(func)
{
	var oldonload = window.onload;
	
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function() {
			if (oldonload)
			{
				oldonload();
			}	
			func();
		}
	}
}

/*******************************************************
	Foto album
*******************************************************/

function prepareGallery()
{
	if (document.getElementById && document.getElementsByTagName)
	{
		if ($('imagegallery'))
		{
			var gallery = $('imagegallery');
			var links = gallery.getElementsByTagName('a');
			
			for (var i = 0; i < links.length; i++)
			{
				links[i].onclick = function() {
					return showPic(this);
				}
			}
		}
	}
}

/*******************************************************
	Visa bild
*******************************************************/

function showPic(whichpic)
{
	if (document.getElementById)
	{
		Effect.Pulsate('placeholder');
		$('placeholder').src = whichpic.href;
		
		if (whichpic.title)
		{
			$('desc').childNodes[0].nodeValue = whichpic.title;
		}
		else
		{
			$('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
		}
		return false;
	}
	else
	{
		return true;
	}
}


/*******************************************************
	AutoCompleter
*******************************************************/

function ajaxAuto()
{
	new Ajax.Autocompleter('txtUser', 'txtAnswer', 'users.asp');
}


/*******************************************************
	Hämta länkar
*******************************************************/
		
function getLinks()
{
	if (document.getElementById && document.getElementsByName)
	{
		if ($('nav'))
		{
			var div = $('nav');
			var links = div.getElementsByTagName('a');
			
			for (var i = 0; i < links.length; i++)
			{
				links[i].onclick = function() {
					Effect.toggle('headerG', 'BLIND');
					};
			}
		}	
	}
}


/*******************************************************
	Ladda funktioner
*******************************************************/

//addLoadEvent(ajaxAuto);
addLoadEvent(getLinks);


/*******************************************************
	Ladda navigationbilder
*******************************************************/

window.onload = preLoad(
	'img/nav_01_start_01.gif',
	'img/nav_01_start_02.gif',
	'img/nav_02_guest_01.gif',
	'img/nav_02_guest_02.gif',
	'img/nav_03_calendar_01.gif',
	'img/nav_03_calendar_02.gif',
	'img/nav_04_link_01.gif',
	'img/nav_04_link_02.gif',
	'img/nav_05_kronikor_01.gif',
	'img/nav_05_kronikor_02.gif');

function preLoad()
{
	var args = preLoad.arguments;
	document.imageArray = new Array(args.length);
	
	for (var i=0; i < args.length; i++)
	{
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i];
	}
}


/*******************************************************
	Lägga till gästboksmeddelande
*******************************************************/

function addGuestbookMessage()
{
	with (window.document.guestbookform)
	{
		if ($F('guestbookname') == '')
		{
			alert("Du måste fylla i ditt namn");
			$('guestbookname').focus();
		}
		else if ($F('guestbookmessage') == '')
		{
			alert("Du måste fylla i ett meddelande");
			$('guestbookmessage').focus();
		}
		else if ($F('validator') == '')
		{
			alert("Du måste fylla i texten från bilden för att kunna spara ditt meddelande");
			$('validator').focus();
		}
		else
		{
			submit();	
		}
	}
}


/*******************************************************
	Lägga till kommentar
*******************************************************/

function addComment()
{
	with (window.document.commentForm)
	{
		if ($F('commentName') == '')
		{
			alert("Du måste fylla i ditt namn");
			$('commentName').focus();
		}
		else if ($F('commentEmail') == '')
		{
			alert("Du måste fylla i din E-post adress");
			$('commentEmail').focus();
		}
		else if ($F('commentMessage') == '')
		{
			alert("Du måste fylla i ett meddelande");
			$('commentMessage').focus();				
		}
		else
		{
			submit();	
		}
	}
}


/*******************************************************
	Lägga till prenumerant
*******************************************************/

function addSubscription()
{
	with (window.document.subscribeForm)
	{
		if ($F('subscriptionname') == '')
		{
			alert("Du måste fylla i ditt namn");
			$('subscriptionname').focus();
		}
		else if ($F('subscriptionemail') == '')
		{
			alert("Du måste fylla i din epost adress");
			$('subscriptionemail').focus();
		}
		else
		{
			if ($F('subscriptionname') != 'Namn' && $F('subscriptionemail') != 'E-post')
			{
				submit();
			}
			else
			{
				alert("Du måste fylla i dina uppgifter");
				$('subscriptionname').select();
			}
		}
	}
}

/*******************************************************
	Lägga till länk
*******************************************************/

function addLink()
{
	with (window.document.linkform)
	{
		if ($F('linkname') == '')
		{
			alert("Du måste fylla i ditt namn");
			$('linkname').focus();
		}
		else if ($F('linkheading') == '')
		{
			alert("Du måste fylla i en rubrik");
			$('linkheading').focus();
		}
		else if ($F('linkurl') == '')
		{
			alert("Du måste ange en adress");
			$('linkurl').focus();
		}
		else if ($F('validator') == '')
		{
			alert("Du måste fylla i texten från bilden för att kunna spara ditt meddelande");
			$('validator').focus();
		}
		else
		{
			submit();	
		}
	}
}


/*******************************************************
	Lägga till en lista
*******************************************************/

function addList()
{
	with (window.document.listform)
	{
		if ($F('listname') == '')
		{
			alert("Du måste fylla i ditt namn");
			$('listname').focus();
		}
		else if ($F('listheading') == '')
		{
			alert("Du måste fylla i en rubrik");
			$('listheading').focus();
		}
		else if ($F('listitem1') == '')
		{
			alert("Du måste fylla i en listpost");
			$('listitem1').focus();
		}
		else if ($F('listitem2') == '')
		{
			alert("Du måste fylla i en listpost");
			$('listitem2').focus();
		}
		else if ($F('listitem3') == '')
		{
			alert("Du måste fylla i en listpost");
			$('listitem3').focus();
		}
		else if ($F('listitem4') == '')
		{
			alert("Du måste fylla i en listpost");
			$('listitem4').focus();
		}
		else if ($F('listitem5') == '')
		{
			alert("Du måste fylla i en listpost");
			$('listitem5').focus();
		}
		else if ($F('listitem6') == '')
		{
			alert("Du måste fylla i en listpost");
			$('listitem6').focus();
		}
		else if ($F('listitem7') == '')
		{
			alert("Du måste fylla i en listpost");
			$('listitem7').focus();
		}
		else if ($F('listitem8') == '')
		{
			alert("Du måste fylla i en listpost");
			$('listitem8').focus();
		}
		else if ($F('listitem9') == '')
		{
			alert("Du måste fylla i en listpost");
			$('listitem9').focus();
		}
		else if ($F('listitem10') == '')
		{
			alert("Du måste fylla i en listpost");
			$('listitem10').focus();
		}
		else
		{
			submit();	
		}
	}
}


/*******************************************************
	Länkhub
*******************************************************/

function forwardURL(target)
{
	document.location.href = target;
}

function changeCategory()
{
	var sel = $('selCategory').value;
	
	if (sel == 0)
	{
		document.location.href = "/links/";	
	}
	else
	{	
		document.location.href = "/links/?orderby=" + sel;
	}
}

function changeWeek(val)
{
	var now = $('weeklist').value;
	var then = $('weeklistLast').value;
	var sp1 = now.split(",");
	var sp2 = then.split(",");
	
	if (val == 0)
	{
		document.location.href = "/list/?week=" + sp1[0] + "&year=" + sp1[1];
	}
	else
	{
		document.location.href = "/list/?week=" + sp2[0] + "&year=" + sp2[1];
	}
}


function viewPic(img)
{ 	
    picfile = new Image(); 
    picfile.src =(img); 
    fileCheck(img); 
}

function fileCheck(img)
{ 	
    if( (picfile.width!=0) && (picfile.height!=0) )
    { 
        makeWindow(img); 
    }
    else 
    {
        funzione="fileCheck('"+img+"')"; 
        intervallo=setTimeout(funzione,50); 
    }
}

function makeWindow(img)
{ 	
    ht = picfile.height + 20;
    wd = picfile.width + 20; 

    var args= "height=" + ht + ",innerHeight=" + ht;
    args += ",width=" + wd + ",innerWidth=" + wd;
    if (window.screen) 
    { 
        var avht = screen.availHeight; 
        var avwd = screen.availWidth;
        var xcen = (avwd - wd) / 2; 
        var ycen = (avht - ht) / 2;
        args += ",left=" + xcen + ",screenX=" + xcen;
        args += ",top=" + ycen + ",screenY=" + ycen + ",resizable=yes"; 	
    }
    return window.open(img, '', args); 
}