function bild(filename) {
    var myImage = new Image();
    myImage.src=filename;
    properties='toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=no,resizable=yes,height=400,width=500';
    var imgWindow = window.open('','',properties);
    
    html = '<html>';
    html += '<head>';
    html += '<title>Hjo Missionskyrka - bild</title>';
    html += '</head>';
    html += '<body topmargin="0" marginheight="0" leftmargin="0" marginwidth="0">';
    html += '<img src="' +myImage.src+ '" onLoad="resizeTo(document.bild.width+9,document.bild.height+60);" name="bild" style="cursor: hand;" OnClick="self.close();">';
    html += '</body>';
    html += '</html>';
    
    imgWindow.document.write(html);
}
function isDigits(str) {
		return /^\d+$/.test(str);
}
function newwin(source,name,width,height,scrolling) {
	specs = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+scrolling+",resizable=no,width=" + width + ",height=" + height;
	popup = window.open(source,name,specs);
	popup.focus();
}

	function validEmail(theEntry) {
		invalidChars = " /:,;"		
		if (theEntry == "") { 
			return false;
			}
		for (i=0; i < 5; i++)  {
			badChar = invalidChars.charAt(i)
				if (theEntry.indexOf(badChar,0) > -1) {
				return false;
				}
		}	
	atsignLoc = theEntry.indexOf("@",1)
		if (atsignLoc == -1) {
			return false;
		}		
		if (theEntry.indexOf("@",atsignLoc+1) > -1) {
		badEntry = "fel1"
		}
	dotLoc = theEntry.indexOf(".",atsignLoc)
		if (dotLoc == -1) {
		return false;
		}
		if (dotLoc+3 > theEntry.length) {
		return false;
		}
	}
function isDigits(str) {
	return /^\d+$/.test(str);
}
	
function validPnr(pnr){
   var ftal;
   var sista;
   re1=/^(\d{0})(\d{6})-(\d{4})$/;
   re2=/^(\d{0})(\d{6})(\d{4})$/;
   
   if(re1.test(pnr)){
      century=pnr.replace(re1 , "$1");
      ftal=pnr.replace(re1 , "$2");
      sista=pnr.replace(re1 , "$3");
   }
   else if(re2.test(pnr)){
      century=pnr.replace(re2 , "$1");
      ftal=pnr.replace(re2 , "$2");
      sista=pnr.replace(re2 , "$3");
   }
   else{
      return false;
   }
   //Kontrollera om kontrollsiffran st&auml;mmer
   if (pernr(ftal,sista)){
     return true; //century+ftal+"-"+sista;
   } else{
   	return false;}
}

function pernr(ftal, sista){
   var sum=0;
   var tal;

   //Kontrollsiffran s&auml;tts till den
   //sista siffran i "sista"

   var kontrollSiffra=sista%10;
   var rest;
   var i;

   rest=100000;

   //loopar igenom f&ouml;delsetalet

   for(i=1;i<=6;i++){
      //tal f&aring;r v&auml;rdet av den i:te siffran
      //i f&ouml;delsetalet
      tal=(ftal/rest)%10;
      temp_tal=parseInt(tal);
      tal=temp_tal;

      //till sum l&auml;ggs siffersumman av tal 
      //multiplicerat med 1 eller 2, 
      //beroende p&aring; position
      sum+=siffersumma(tal*(1+i%2));
      rest/=10;
   }
   rest=1000;

   //loopar igenom tre f&ouml;rsta siffrorna
   //bland de fyra sista siffrorna

   for(i=1;i<4;i++){
      tal=(sista/rest)%10;
      temp_tal=parseInt(tal);
      tal=temp_tal;
      sum+=siffersumma(tal*(1+i%2));
      rest/=10;

      temp_sum=parseInt(sum);
      sum=temp_sum;
  }

   //sum s&auml;tts till differensen mellan
   //sum och n&auml;rmast st&ouml;rre 10-tal

   if (sum%10){
      temp_sum=parseInt(sum/10+1);
      sum=temp_sum*10-sum;
   }
   else{
      sum=0;
   }

   //om sum st&auml;mmer &ouml;verens med
   //kontrollsiffra returneras 1,
   //annars 0

   return (sum==kontrollSiffra);
}

function siffersumma(tal){
   var summa=0;
   while(tal>=1){
      temp_tal=parseInt(tal);
      tal=temp_tal;
      summa=summa+tal%10;
      temp_summa=parseInt(summa);
      summa=temp_summa;
      tal=tal/10;
   }
   return summa;
}
