/**
 *  File for printing resultlist for searching in REG on searchResult.jsp
 *
 */

function regReceiverFunc(searchresult)
{

 //creates and sets values for parsing REG results
  var htmlTextAtgardHits=false, lastListhit=0, nextLine="", next=0, htmlTextDocumentAccessCode = "", htmlTextAktNr = "", htmlTextArtal = "", htmlTextAtgard = "", htmlText = "";
  fmr = parseInt(document.getElementById('firstMatchToReturnREG').value);

  if(fmr > (searchresult.totalMatches - (fmr + 10))){
    if(searchresult.totalMatches - fmr >= 10){
      lastListhit = fmr + 10 - 1;
    }
    else{lastListhit = searchresult.totalMatches; }
  }
  else{lastListhit = fmr+9;}

  if(searchresult.totalMatches==0){
    fmr=0;
  }

  //deletes loading-image
  while (document.getElementById("REGhits").childNodes.length > 0)
  document.getElementById("REGhits").removeChild(document.getElementById("REGhits").firstChild);

  //adds header for REG
  var tbod=document.getElementById("REGhits");
  var trow = document.createElement("tr");
  var th1 = document.createElement("th");
  if(document.getElementById("user").value=="member"){
    th1.setAttribute("colSpan", "4");
  }
  else{th1.setAttribute("colSpan", "3");}
  th1.appendChild(document.createTextNode(propertyREGName));
  if(fmr>0){
      var span = document.createElement("span");
    if(searchresult.totalMatches>10)
      span.appendChild(document.createTextNode(" "+fmr + "-" + (lastListhit) + " "+propertyTotal+" " + searchresult.totalMatches+" "+propertyHits));
    else if(searchresult.totalMatches==1)
      span.appendChild(document.createTextNode(" "+searchresult.totalMatches+" "+propertyHit));
    else
      span.appendChild(document.createTextNode(" "+searchresult.totalMatches+" "+propertyHits));
    th1.appendChild(span);
 }

  trow.appendChild(th1);
  tbod.appendChild(trow);


 var linkInfo = document.createElement("a");
      linkInfo.setAttribute("href", "javascript:showHideREGInfo();");
       var imgInfo = document.createElement("img");
      imgInfo.src="../images/info.gif";
      imgInfo.alt=propertyHelptext;
      imgInfo.title=propertyHelptext;
      linkInfo.appendChild(imgInfo);
      th1.appendChild(linkInfo);
      trow.appendChild(th1);
      tbod.appendChild(trow);


    var trowInfo = document.createElement("tr");
    trowInfo.setAttribute("id","regInfo");
     trowInfo.className='descriptionHidden';
    var tdInfo = document.createElement("td");
	 tdInfo.setAttribute("id","regInfoTD");
    if(document.getElementById("user").value=="member"){
      tdInfo.setAttribute("colSpan", "4");
    }
    else{tdInfo.setAttribute("colSpan", "3");}
     var spanInfo = document.createElement("span");
     spanInfo.appendChild(document.createTextNode(propertyREGDescription));
     tdInfo.appendChild(spanInfo);
     trowInfo.appendChild(tdInfo);
     tbod.appendChild(trowInfo);

  if(fmr==0){
    tbod.appendChild(createInfoRow(propertyNoHits));
  }else if(searchresult.totalMatches > 10000){
    tbod.appendChild(createInfoRow(propertyToManyHits));
  }else{

  var tempATG="", firstLetterATG="", lastLettersATG="";
  for(var i=0; i<searchresult.documents.length; i++)
  {
    var nbOfImages=0;
    htmlTextArtal="";
    for(var j=0; j<searchresult.documents[i].paragraphs.length; j++)
    {
        if(searchresult.documents[i].paragraphs[j].name == "AFDS"){
         htmlTextAktNr = searchresult.documents[i].paragraphs[j].text;
        }
		
		if(searchresult.documents[i].paragraphs[j].name == "PULD"){
			if(searchresult.documents[i].paragraphs[j].text == "99999999"){
				htmlTextArtal ="-";
			}
			else{
         		htmlTextArtal = searchresult.documents[i].paragraphs[j].text.substring(0,4);
			}
        }

        //if(searchresult.documents[i].paragraphs[j].name == "BASE"){
         //htmlTextArtal = searchresult.documents[i].paragraphs[j].text;
        //}
        if(searchresult.documents[i].paragraphs[j].name == "ANBI"){
         nbOfImages = searchresult.documents[i].paragraphs[j].text;
        }

     }
    htmlTextAtgardHits=false;
		htmlTextAtgard = "";
    for(var k=0; k<searchresult.documents[i].paragraphGroups.length; k++)
    {
        if(searchresult.documents[i].paragraphGroups[k].name == "ATG"){

          for(var l=0; l<searchresult.documents[i].paragraphGroups[k].paragraphs.length; l++){

              if(searchresult.documents[i].paragraphGroups[k].paragraphs[l].name == "ATGBESK"){
                  tempATG="";
                  firstLetterATG="";
                  lastLettersATG="";
                  tempATG=searchresult.documents[i].paragraphGroups[k].paragraphs[l].text.toLowerCase();
                  firstLetterATG=tempATG.substring(0,1).toUpperCase();
                  lastLettersATG=tempATG.substring(1,tempATG.length);
                  tempATG=firstLetterATG+lastLettersATG;
                  htmlTextAtgardHits=true;
                  if(tempATG!=""){
                    htmlTextAtgard += tempATG+", ";
                  }
               }
           }
        }
        else if(searchresult.documents[i].paragraphGroups[k].name == "PLAN"){

          for(var l=0; l<searchresult.documents[i].paragraphGroups[k].paragraphs.length; l++){

              if(searchresult.documents[i].paragraphGroups[k].paragraphs[l].name == "PLLN"){
                  tempATG="";
                  firstLetterATG="";
                  lastLettersATG="";
                  tempATG=searchresult.documents[i].paragraphGroups[k].paragraphs[l].text.toLowerCase();
                  firstLetterATG=tempATG.substring(0,1).toUpperCase();
                  lastLettersATG=tempATG.substring(1,tempATG.length);
                  tempATG=firstLetterATG+lastLettersATG;
                  htmlTextAtgardHits=true;
                  if(tempATG!=""){
                    htmlTextAtgard += tempATG+", ";
                  }
               }
           }
        }
        else if(k==searchresult.documents[i].paragraphGroups.length-1){
          htmlTextAtgard += "- ";
        }
    }

    if(htmlTextAtgardHits==true){
       htmlTextAtgard=htmlTextAtgard.substring(0,(htmlTextAtgard.length-2));
       htmlTextAtgard = trimString(htmlTextAtgard);
       if(htmlTextAtgard.substring(htmlTextAtgard.length-1,htmlTextAtgard.length)==","){
          htmlTextAtgard = htmlTextAtgard.substring(0,htmlTextAtgard.length-1);
       }
    }

    //create and adds table cells with values
     var trow = document.createElement("tr");

     //adds column with link to map
     if(nbOfImages>0){
        var images="";
        if(nbOfImages=="1")
          images=propertyImage;
        else
         images=propertyImages;
      if(document.getElementById("user").value=="member"){
        var td1 = document.createElement("td");
        var link = document.createElement("a");
        link.setAttribute("href", "show.html?showmap=true&archive=REG&nbOfImages="+nbOfImages+"&sd_base="+searchresult.documents[i].base+"&sd_ktun="+searchresult.documents[i].ktun);
        link.appendChild(document.createTextNode(htmlTextAktNr+" ("+nbOfImages+" "+images+")"));
        td1.appendChild(link);
        trow.appendChild(td1);
      }
      else{
        var td1 = document.createElement("td");
        var link = document.createElement("a");
        link.setAttribute("href", "show.html?showmap=true&archive=REG&nbOfImages="+nbOfImages+"&sd_base="+searchresult.documents[i].base+"&sd_ktun="+searchresult.documents[i].ktun);
        link.appendChild(document.createTextNode(htmlTextAktNr));
        td1.appendChild(link);
        trow.appendChild(td1);
      }
     }
     else{
       var td1 = document.createElement("td");
       td1.appendChild(document.createTextNode(htmlTextAktNr));
       trow.appendChild(td1);
     }

    //adds column with task
     var td2 = document.createElement("td");
     if(htmlTextAtgard!=""){
      td2.appendChild(document.createTextNode(htmlTextAtgard));
     }
     else{
      td2.appendChild(document.createTextNode("-"));
     }
     trow.appendChild(td2);

    //adds column with year
     var td3 = document.createElement("td");
     if(htmlTextArtal.length>4)
       htmlTextArtal=htmlTextArtal.substring(0,4);
     if(htmlTextArtal==""||htmlTextArtal=="0000")
      td3.appendChild(document.createTextNode("-"));
     else{
      td3.appendChild(document.createTextNode(htmlTextArtal));
     }
     trow.appendChild(td3);

    //adds forth column for members
     if(document.getElementById("user").value=="member"){
         var td4 = document.createElement("td");
         var link2 = document.createElement("a");
         link2.setAttribute("href", "show.html?showmap=false&archive=REG&nbOfImages="+nbOfImages+"&sd_base="+searchresult.documents[i].base+"&sd_ktun="+searchresult.documents[i].ktun);
         link2.appendChild(document.createTextNode("Info"));
         td4.appendChild(link2);
         trow.appendChild(td4);
     }

     tbod.appendChild(trow);

      htmlTextAtgard = "";
      htmlTextArtal = "";

  }

  //Next hit in searchresultlist
  var l=1;
  var bolForegaende=false;
  var current=0;
  var htmlTextF="";

  trow = document.createElement("tr");
  td1 = document.createElement("td");
  if(document.getElementById("user").value=="member"){
    td1.setAttribute("colSpan", "4");
  }
  else{td1.setAttribute("colSpan", "3");}
  td1.className='pages';


  if(Math.ceil(fmr/10)  > 10+1){//sets startvalues for l in for-loop
    l = Math.ceil(fmr/10) - 10;
  }

 if(lastListhit>=10){//Dont write any numbers if lastListhit>=10
  for(l; l<=(Math.ceil(searchresult.totalMatches/10)); l++){

    if((l*(10-1)) > searchresult.totalMatches+10 || (l >= Math.ceil(fmr/10) + 10))
    {
      break;
    }
    else{

      if(((l*10) >= fmr) && ((l*10)<= fmr+10)){
        if(parseInt(searchresult.totalMatches)!=10){
          var strongele = document.createElement("strong");  //create number currentpage
          strongele.appendChild(document.createTextNode(parseInt(l)));
          td1.appendChild(strongele);
        }
        current=l;
      }
      else{
        var link = document.createElement("a");  //create link with number
        link.setAttribute("href", "searchresult.html?archive="+document.getElementById('archive').value +"&firstMatchToReturnLMS="+parseInt(document.getElementById('firstMatchToReturnLMS').value)+"&firstMatchToReturnRAK="+document.getElementById('firstMatchToReturnRAK').value+"&firstMatchToReturnREG="+parseInt(((l*10)+1)-10)+"&yMin="+document.getElementById('yMin').value+"&xMin="+document.getElementById('xMin').value+"&yMax="+document.getElementById('yMax').value+"&xMax="+document.getElementById('xMax').value);
        link.appendChild(document.createTextNode(parseInt(l)));
        td1.appendChild(link);
      }
   }

  }
  if((l-1)!=current || lastListhit<searchresult.totalMatches){
    var link = document.createElement("a");  //create link with next
    var linkLast = document.createElement("a");  //create link with next
    var last=searchresult.totalMatches;
    //calculate
    last=calculateLast(last);

    link.setAttribute("href", "searchresult.html?archive="+document.getElementById('archive').value+"&firstMatchToReturnLMS="+parseInt(document.getElementById('firstMatchToReturnLMS').value)+"&firstMatchToReturnRAK="+document.getElementById('firstMatchToReturnRAK').value+"&firstMatchToReturnREG="+parseInt(fmr+10)+"&yMin="+document.getElementById('yMin').value+"&xMin="+document.getElementById('xMin').value+"&yMax="+document.getElementById('yMax').value+"&xMax="+document.getElementById('xMax').value);
    link.appendChild(document.createTextNode(propertyNext));

    linkLast.setAttribute("href", "searchresult.html?archive="+document.getElementById('archive').value+"&firstMatchToReturnLMS="+parseInt(document.getElementById('firstMatchToReturnLMS').value)+"&firstMatchToReturnRAK="+document.getElementById('firstMatchToReturnRAK').value+"&firstMatchToReturnREG="+last+"&yMin="+document.getElementById('yMin').value+"&xMin="+document.getElementById('xMin').value+"&yMax="+document.getElementById('yMax').value+"&xMax="+document.getElementById('xMax').value);
    linkLast.appendChild(document.createTextNode(propertyLast));

    td1.appendChild(link);
    td1.appendChild(linkLast);

  }
  if(current>1){
    //create link with previous
    var linkPrevious = document.createElement("a");
    linkPrevious.setAttribute("href", "searchresult.html?archive="+document.getElementById('archive').value+"&firstMatchToReturnLMS="+parseInt(document.getElementById('firstMatchToReturnLMS').value)+"&firstMatchToReturnRAK="+document.getElementById('firstMatchToReturnRAK').value+"&firstMatchToReturnREG="+parseInt(fmr-10)+"&yMin="+document.getElementById('yMin').value+"&xMin="+document.getElementById('xMin').value+"&yMax="+document.getElementById('yMax').value+"&xMax="+document.getElementById('xMax').value);
    linkPrevious.appendChild(document.createTextNode(propertyPrevious));
    td1.insertBefore(linkPrevious,td1.firstChild);
    //create link with first
    var linkFirst = document.createElement("a");
    linkFirst.setAttribute("href", "searchresult.html?archive="+document.getElementById('archive').value+"&firstMatchToReturnLMS="+parseInt(document.getElementById('firstMatchToReturnLMS').value)+"&firstMatchToReturnRAK="+document.getElementById('firstMatchToReturnRAK').value+"&firstMatchToReturnREG=1&yMin="+document.getElementById('yMin').value+"&xMin="+document.getElementById('xMin').value+"&yMax="+document.getElementById('yMax').value+"&xMax="+document.getElementById('xMax').value);
    linkFirst.appendChild(document.createTextNode(propertyFirst));
    td1.insertBefore(linkFirst,td1.firstChild);
  }
  }

  var lastListhit=0, nextLine="", next=0, htmlTextDocumentAccessCode = "", htmlTextAktNr = "", htmlTextArtal = "", htmlTextAtgard = "", htmlText = "";


  fmr = parseInt(document.getElementById('firstMatchToReturnREG').value);

  if(fmr > (searchresult.totalMatches - (fmr + 10))){
    if(searchresult.totalMatches - fmr >= 10){
      lastListhit = fmr + 10 - 1;
    }
    else{
    lastListhit = searchresult.totalMatches;
    }

  }
  else{
    lastListhit = fmr+9;
  }


  if(lastListhit>=10 && (searchresult.totalMatches <10 || searchresult.totalMatches >10)){
  	if(parseInt(searchresult.totalMatches)!=10){//if exactly 10 hits dont show number 1
    	trow.appendChild(td1);
	}
    tbod.appendChild(trow);
  }

  }
}

function regReceiverFuncAdvanced(searchresult)
{
  //creates and sets values for parsing REG results
  var bokmText=false, htmlTextAtgardHits=false, lastListhit=0, htmlTextVars = "", nextLine="", next=0, htmlTextDocumentAccessCode = "", htmlTextAktNr = "", htmlTextArtal = "", htmlTextAtgard = "", htmlText = "";
  var searchType=document.getElementById("searchType").value;
  fmr = parseInt(document.getElementById("firstMatchToReturnREG").value);

  if(fmr > (searchresult.totalMatches - (fmr + 10))){
    if(searchresult.totalMatches - fmr >= 10){
      lastListhit = fmr + 10 - 1;
    }
    else{lastListhit = searchresult.totalMatches; }
  }
  else{lastListhit = fmr+9;}

  if(searchresult.totalMatches==0){
    fmr=0;
  }

  //deletes loading-image
  while (document.getElementById("REGhits").childNodes.length > 0)
  document.getElementById("REGhits").removeChild(document.getElementById("REGhits").firstChild);

  //adds header for REG
  var tbod=document.getElementById("REGhits");
  var trow = document.createElement("tr");
  var th1 = document.createElement("th");
  if(document.getElementById("user").value=="member"){
    th1.setAttribute("colSpan", "4");
  }
  else{th1.setAttribute("colSpan", "3");}
  th1.appendChild(document.createTextNode(propertyREGName));
  if(fmr>0){
    var span = document.createElement("span");
    if(searchresult.totalMatches>10)
      span.appendChild(document.createTextNode(" "+fmr + "-" + (lastListhit) + " "+propertyTotal+" " + searchresult.totalMatches+" "+propertyHits));
    else if(searchresult.totalMatches==1)
      span.appendChild(document.createTextNode(" "+searchresult.totalMatches+" "+propertyHit));
    else
      span.appendChild(document.createTextNode(" "+searchresult.totalMatches+" "+propertyHits));
    th1.appendChild(span);
 }

  trow.appendChild(th1);
  tbod.appendChild(trow);

  if(fmr==0){
    tbod.appendChild(createInfoRow(propertyNoHits));
  }else if(searchresult.totalMatches > 10000){
    tbod.appendChild(createInfoRow(propertyToManyHits));
  }else{
  var tempATG="", firstLetterATG="", lastLettersATG="";
  for(var i=0; i<searchresult.documents.length; i++)
    {
    htmlTextVars="";
    var hasMap=false;
    var nbOfImages=0;
    htmlTextArtal="";
    for(var j=0; j<searchresult.documents[i].paragraphs.length; j++)
    {
        if(searchresult.documents[i].paragraphs[j].name == "AFDS"){
         htmlTextAktNr = searchresult.documents[i].paragraphs[j].text;
          htmlTextVars += "&designation=" + searchresult.documents[i].paragraphs[j].text;
        }
        if(searchresult.documents[i].paragraphs[j].name == "PULD"){
			if(searchresult.documents[i].paragraphs[j].text == "99999999" || searchresult.documents[i].paragraphs[j].text == "00000000"){
				htmlTextArtal ="-";
			}
			else{
         		htmlTextArtal = searchresult.documents[i].paragraphs[j].text.substring(0,4);
			}
        }
        //if(searchresult.documents[i].paragraphs[j].name == "BASE"){
         //htmlTextVars += "&database=" + searchresult.documents[i].paragraphs[j].text;
        //}
        if(searchresult.documents[i].paragraphs[j].name == "ANBI"){
         nbOfImages = searchresult.documents[i].paragraphs[j].text;
        }
		
         if(searchresult.documents[i].paragraphs[j].name == "KART"){
          if(searchresult.documents[i].paragraphs[j].text=="J"){
            hasMap=true;
          }
        }
     }

        for(var t=0; t<searchresult.documents[i].paragraphGroups.length; t++)
        {
           if(searchresult.documents[i].paragraphGroups[t].name == "BOKM"){
            bokmText=true;
           }
        }


    htmlTextAtgard = "";
    htmlTextAtgardHits=false;

    for(var k=0; k<searchresult.documents[i].paragraphGroups.length; k++)
    {
        if(searchresult.documents[i].paragraphGroups[k].name == "ATG"){
          for(var l=0; l<searchresult.documents[i].paragraphGroups[k].paragraphs.length; l++){
              if(searchresult.documents[i].paragraphGroups[k].paragraphs[l].name == "ATGBESK"){

                  tempATG="";
                  firstLetterATG="";
                  lastLettersATG="";
                  tempATG=searchresult.documents[i].paragraphGroups[k].paragraphs[l].text.toLowerCase();
                  firstLetterATG=tempATG.substring(0,1).toUpperCase();
                  lastLettersATG=tempATG.substring(1,tempATG.length);
                  tempATG=firstLetterATG+lastLettersATG;
                  if(tempATG!=""){
                    htmlTextAtgard += tempATG+", ";
                  }
                  htmlTextAtgardHits=true;
              }
           }
        }
        else if(searchresult.documents[i].paragraphGroups[k].name == "PLAN"){
          for(var l=0; l<searchresult.documents[i].paragraphGroups[k].paragraphs.length; l++){
              if(searchresult.documents[i].paragraphGroups[k].paragraphs[l].name == "PLLN"){
                  tempATG="";
                  firstLetterATG="";
                  lastLettersATG="";
                  tempATG=searchresult.documents[i].paragraphGroups[k].paragraphs[l].text.toLowerCase();
                  firstLetterATG=tempATG.substring(0,1).toUpperCase();
                  lastLettersATG=tempATG.substring(1,tempATG.length);
                  tempATG=firstLetterATG+lastLettersATG;
                  if(tempATG!=""){
                    htmlTextAtgard += tempATG+", ";
                  }
                  htmlTextAtgardHits=true;
               }
           }
        }
        else if(k==searchresult.documents[i].paragraphGroups.length-1){
          htmlTextAtgard += "- ";
        }
    }


    if(htmlTextAtgardHits==true){
       htmlTextAtgard=htmlTextAtgard.substring(0,(htmlTextAtgard.length-2));
       htmlTextAtgard = trimString(htmlTextAtgard);
       if(htmlTextAtgard.substring(htmlTextAtgard.length-1,htmlTextAtgard.length)==","){
          htmlTextAtgard = htmlTextAtgard.substring(0,htmlTextAtgard.length-1);
       }
    }


    htmlTextVars += "&task=" + htmlTextAtgard;

    //create table rows
     var trow = document.createElement("tr");
     //adds first column for member with link to map
     var td1 = document.createElement("td");

     if(nbOfImages>0){
        var images="";
        if(nbOfImages=="1")
          images=propertyImage;
        else
         images=propertyImages;
           var link = document.createElement("a");
           var ul = document.createElement("ul");
           var li = document.createElement("li");
            link.setAttribute("href", "show.html?archive=REG&showmap=true&searchType="+searchType+"&nbOfImages="+nbOfImages+"&sd_base="+searchresult.documents[i].base+"&sd_ktun="+searchresult.documents[i].ktun);
           if(document.getElementById("user").value=="member"){
            if(bokmText==true){
              link.appendChild(document.createTextNode(htmlTextAktNr+" ("+nbOfImages+" "+images+") ("+propertyBookmark+")"));
              bokmText=false;
            }
            else{
              link.appendChild(document.createTextNode(htmlTextAktNr+" ("+nbOfImages+" "+images+")"));
            }

           }
           else{
            link.appendChild(document.createTextNode(htmlTextAktNr));
           }

           td1.appendChild(link);
           trow.appendChild(td1);

      }
       else{
          td1.appendChild(document.createTextNode(htmlTextAktNr));
          trow.appendChild(td1);
        }

     //adds second column with task
     var td2 = document.createElement("td");
     if(htmlTextAtgard!="")
      td2.appendChild(document.createTextNode(htmlTextAtgard));
     else
      td2.appendChild(document.createTextNode("-"));
     trow.appendChild(td2);

     //adds third column with year
     var td3 = document.createElement("td");
     if(htmlTextArtal.length>4)
       htmlTextArtal=htmlTextArtal.substring(0,4);
     if(htmlTextArtal==""||htmlTextArtal=="0000")
      td3.appendChild(document.createTextNode("-"));
     else{
      td3.appendChild(document.createTextNode(htmlTextArtal));
     }
     trow.appendChild(td3);

     //adds forth column for member with link to text
     if(document.getElementById("user").value=="member"){
         var td4 = document.createElement("td");
         var link2 = document.createElement("a");
         link2.setAttribute("href", "show.html?archive=REG&showmap=false&searchType="+searchType+"&sd_base="+searchresult.documents[i].base+"&sd_ktun="+searchresult.documents[i].ktun);
         link2.appendChild(document.createTextNode("Info"));
         td4.appendChild(link2);
         trow.appendChild(td4);
     }
     //adds row to table
     tbod.appendChild(trow);
  }

  //Next hit in searchresultlist
  var l=1;
  var bolForegaende=false;
  var current=0;
  var htmlTextF="";

  trow = document.createElement("tr");
  td1 = document.createElement("td");
  if(document.getElementById("user").value=="member"){
    td1.setAttribute("colSpan", "4");
  }
  else{td1.setAttribute("colSpan", "3");}
  td1.className='pages';
  //td1.setAttribute("class", "pages");

  if(Math.ceil(fmr/10)  > 10+1){//sets startvalues for l in for-loop
    l = Math.ceil(fmr/10) - 10;
  }

 if(lastListhit>=10){//Dont write any numbers if lastListhit>=10
  for(l; l<=(Math.ceil(searchresult.totalMatches/10)); l++){
    if((l*(10-1)) > searchresult.totalMatches+10 || (l >= Math.ceil(fmr/10) + 10))
    {
      break;
    }
    else{

      if(((l*10) >= fmr) && ((l*10)<= fmr+10)){
       var strongele = document.createElement("strong");  //create number currentpage
       strongele.appendChild(document.createTextNode(parseInt(l)));
       td1.appendChild(strongele);
       current=l;
      }
      else{
        var link = document.createElement("a");  //create link with number
        if(document.getElementById('historyId') != null && document.getElementById('historyId').value.length > 0){
	  link.setAttribute("href", createRegLnkHistory(parseInt(((l*10)+1)-10)));
	}else{
	  link.setAttribute("href", createRegLnk(parseInt(((l*10)+1)-10), searchType));
	}
        link.appendChild(document.createTextNode(parseInt(l)));
        td1.appendChild(link);
      }
   }

  }
  if((l-1)!=current || lastListhit<searchresult.totalMatches){
    var link = document.createElement("a");  //create link with next
    var linkLast = document.createElement("a");  //create link with next
    var last=searchresult.totalMatches;
    //calculate
    last=calculateLast(last);
    if(document.getElementById('historyId') != null && document.getElementById('historyId').value.length > 0){
      link.setAttribute("href", createRegLnkHistory(parseInt(fmr+10)));
    }else{
	link.setAttribute("href", createRegLnk(parseInt(fmr+10), searchType));
    }
    link.appendChild(document.createTextNode(propertyNext));
    if(document.getElementById('historyId') != null && document.getElementById('historyId').value.length > 0){
	linkLast.setAttribute("href", createRegLnkHistory(last));
    }else{
	linkLast.setAttribute("href", createRegLnk(last, searchType));
    }
    linkLast.appendChild(document.createTextNode(propertyLast));

    td1.appendChild(link);
    td1.appendChild(linkLast);

  }
  if(current>1){
    var linkPrevious = document.createElement("a");  //create link with previous
    var linkFirst = document.createElement("a");  //create link with first
    if(document.getElementById('historyId') != null && document.getElementById('historyId').value.length > 0){
	linkPrevious.setAttribute("href", createRegLnkHistory(parseInt(fmr-10)));
        linkFirst.setAttribute("href", createRegLnkHistory(1));
    }else{
	linkPrevious.setAttribute("href", createRegLnk(parseInt(fmr-10), searchType));
        linkFirst.setAttribute("href", createRegLnk(1, searchType));
    }
    linkPrevious.appendChild(document.createTextNode(propertyPrevious));
    linkFirst.appendChild(document.createTextNode(propertyFirst));
    td1.insertBefore(linkPrevious,td1.firstChild);
    td1.insertBefore(linkFirst,td1.firstChild);
  }
  }

  var lastListhit=0, htmlTextVars = "", nextLine="", next=0, htmlTextDocumentAccessCode = "", htmlTextAktNr = "", htmlTextArtal = "", htmlTextAtgard = "", htmlText = "";

  fmr = parseInt(document.getElementById('firstMatchToReturnREG').value);

  if(fmr > (searchresult.totalMatches - (fmr + 10))){
    if(searchresult.totalMatches - fmr >= 10){
      lastListhit = fmr + 10 - 1;
    }
    else{
    lastListhit = searchresult.totalMatches;
    }

  }
  else{
    lastListhit = fmr+9;
  }

  if(lastListhit>=10 && (searchresult.totalMatches <10 || searchresult.totalMatches >10)){
 	if(parseInt(searchresult.totalMatches)!=10){//if exactly 10 hits dont show number 1
    	trow.appendChild(td1);
	}
    tbod.appendChild(trow);

  }
  }
}

function createRegLnkHistory(firstMatchToReturn){
  return "searchresult.html?archive="+document.getElementById('archive').value+"&frSelected="+document.getElementById('frSelected').value+"&firstMatchToReturnREG="+firstMatchToReturn+"&historyId="+document.getElementById('historyId').value;
}

function createRegLnk(firstMatchToReturn, searchType){
  return "searchresult.html?searchTypeMP="+document.getElementById('searchTypeMP').value+"&frSelected="+document.getElementById('frSelected').value+"&munParREG="+document.getElementById('munParREG').value+"&searchType="+searchType+"&archive="+document.getElementById('archive').value+"&firstMatchToReturnREG="+firstMatchToReturn+"&openSearchREG="+document.getElementById("openSearch").value+"&document="+document.getElementById("document").value+"&taskREG="+document.getElementById("task").value+"&countyREG="+document.getElementById("county").value+"&yearMinREG="+document.getElementById("yearMin").value+"&yearMaxREG="+document.getElementById("yearMax").value;
}
