/********************************************************** 
	Ladda händelser 
**********************************************************/

function addLoadEvent(func)
{
  var oldonload = window.onload;
  
  if (typeof window.onload != 'function')
  {
    window.onload = func;
  }
  else
  {
    window.onload = function() {
      if (oldonload) 
	  {
        oldonload();
      }
      func();
    }
  }
}


/********************************************************** 
	Ladda bilder
**********************************************************/

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];
	}
}

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); 
}

/********************************************************** 
	Placera & ta bort obligatoriska bilder
**********************************************************/

function checkField(id,error)
{
	if ($F(id) == '')
	{
		Effect.Appear(error);
		document.getElementById(id).focus();
	}
	else
	{
		Effect.Fade(error);	
	}
}


/********************************************************** 
	Kontrollera formulär innan dom skickas
**********************************************************/

function validateSub()
{
	with (window.document.subForm)
	{
		if ($F('txtName') == '')
		{
			alert('Du har inte fyllt i ditt namn');
			$('txtName').focus();
		}
		else if (isNaN($F('txtPnr')))
		{
			alert('Ditt personnummer måste vara i numeriskt format');
			$('txtPnr').focus();			
		}
		else if($F('txtPnr').length < 6)
		{
			alert('Ditt personnummer måste vara minst 6 siffror');
			$('txtPnr').focus();
		}
		else if ($F('txtPnr') == '')
		{
			alert('Du måste fylla i ditt personnummer');
			$('txtPnr').focus();
		}
		else if ($F('txtAddress') == '')
		{
			alert('Du har inte fyllt i en adress');
			$('txtAddress').focus();		
		}
		else if (isNaN($F('txtZip')))
		{
			alert('Ditt postnummer måste vara i numeriskt format...');
			$('txtZip').focus();			
		}
		else if ($F('txtZip') < 5)
		{
			alert('Ditt postnummer måste vara minst 5 siffror...');
			$('txtZip').focus();
		}
		else if ($F('txtZip') == '')
		{
			alert('Du måste ange ett postnummer');
			$('txtZip').focus();
		}
		else if ($F('txtCity') == '')
		{
			alert('Du har inte fyllt i en ort');
			$('txtCity').focus();			
		}
		else if ($F('txtEmail') == '')
		{
			alert('Du har inte fyllt i din e-post adress');
			$('txtEmail').focus();
		}
		else
		{
			submit();	
		}
	}
}

function validateCon()
{
	with (window.document.contactForm)
	{
		if ($F('txtName') == '')
		{
			alert('Du måste ange ditt namn');
			$('txtName').focus();	
		}
		else if ($F('txtEmail') == '')
		{
			alert('Du har inte fyllt i din e-post adress');
			$('txtEmail').focus();	
		}
		else if ($F('txtMessage') == '')
		{
			alert('Du måste fylla i ett meddelande...');
			$('txtMessage').focus();	
		}
		else
		{
			submit();	
		}
		
	}
}

function validateEmail()
{
	with (window.document.emailForm)
	{
		if ($F('name') == '')
		{
			alert('Du måste fylla i ditt namn');
			$('name').focus();
		}
		else if($F('email') == '')
		{
			alert('Du måste ange en e-post adress');
			$('email').focus();
		}
		else
		{
			submit();	
		}
	}
}

function validate(form)
{
	var returnval = true;

	for (var i = 0; i < form.elements.length; i++)
	{
		if (form.elements[i].type == "text" || form.elements [i].type == "textarea")
		{
			if (form.elements[i].value == "")
			{
				alert("Please make sure all fields are entered");
				returnval = false;
				break;
			}
		}
	}

	return returnval;
}

function checkFields()
{
	var chk = true;
	var args = checkFields.arguments;

	for (var i = 0; i < args.length; i++)
	{
		var thisElement = document.getElementById(args[i]);

		if (thisElement.value == "")
		{
			alert("Alla obligatoriska fält måste vara ifyllda!");
			chk = false;
			break;          
		}
	}

	if (chk == true)
	{
		document.location = document.form.action;
	}
}