function prisliste_download(inID){
try{document.getElementById('dl').innerHTML='<iframe src="/mod_prisliste.asp?id='+inID+'">';}catch(e){alert(e)}
}

function validateContact(){
  var intRes='';
  var o=document.kontakt;
  if(o.beskjed.value==''){intRes='Fyll inn beskjeden du ønsker å sende'}
  if(o.email.value==''){intRes='Fyll inn e-postadresse'}
  if(o.tlf.value==''){intRes='Fyll inn telefonnummer'}
  if(o.adr3.value==''){intRes='Fyll inn adresse'}
  if(o.adr2.value==''){intRes='Fyll inn adresse'}
  if(o.adr1.value==''){intRes='Fyll inn adresse'}
  if(o.navn.value==''){intRes='Fyll inn navn'}
  if(intRes==''){o.submit();}else{alert(intRes)}
}

function Insert1Cell(TableName,CellSpan,CellClass,CellText){
  var r=document.getElementById(TableName).insertRow(-1);
  var c1=r.insertCell(0);
  if(CellSpan!=''){c1.colSpan=CellSpan};
  if(CellClass!=''){c1.className=CellClass};
  c1.innerHTML=CellText;
}

function sendfile(inp){
  document.getElementById('dl').innerHTML='<iframe height=0 width=0 src="sendfiles.asp?filename='+urlencode(inp)+'"></iframe>';
  document.getElementById('dl').style.display='block';
}

function urlencode(str){
  var hash_map={},unicodeStr='',hexEscStr='';
  var ret=(str+'').toString();
  var replacer=function(search,replace,str){var tmp_arr=[];tmp_arr=str.split(search);return tmp_arr.join(replace);};
  hash_map["'"]      = '%27';
  hash_map['(']      = '%28';
  hash_map[')']      = '%29';
  hash_map['*']      = '%2A';
  hash_map['~']      = '%7E';
  hash_map['!']      = '%21';
  hash_map['%20']    = '+';
  hash_map['\u00DC'] = '%DC';
  hash_map['\u00FC'] = '%FC';
  hash_map['\u00C4'] = '%D4';
  hash_map['\u00E4'] = '%E4';
  hash_map['\u00D6'] = '%D6';
  hash_map['\u00F6'] = '%F6';
  hash_map['\u00DF'] = '%DF';
  hash_map['\u20AC'] = '%80';
  hash_map['\u0081'] = '%81';
  hash_map['\u201A'] = '%82';
  hash_map['\u0192'] = '%83';
  hash_map['\u201E'] = '%84';
  hash_map['\u2026'] = '%85';
  hash_map['\u2020'] = '%86';
  hash_map['\u2021'] = '%87';
  hash_map['\u02C6'] = '%88';
  hash_map['\u2030'] = '%89';
  hash_map['\u0160'] = '%8A';
  hash_map['\u2039'] = '%8B';
  hash_map['\u0152'] = '%8C';
  hash_map['\u008D'] = '%8D';
  hash_map['\u017D'] = '%8E';
  hash_map['\u008F'] = '%8F';
  hash_map['\u0090'] = '%90';
  hash_map['\u2018'] = '%91';
  hash_map['\u2019'] = '%92';
  hash_map['\u201C'] = '%93';
  hash_map['\u201D'] = '%94';
  hash_map['\u2022'] = '%95';
  hash_map['\u2013'] = '%96';
  hash_map['\u2014'] = '%97';
  hash_map['\u02DC'] = '%98';
  hash_map['\u2122'] = '%99';
  hash_map['\u0161'] = '%9A';
  hash_map['\u203A'] = '%9B';
  hash_map['\u0153'] = '%9C';
  hash_map['\u009D'] = '%9D';
  hash_map['\u017E'] = '%9E';
  hash_map['\u0178'] = '%9F';
  ret=encodeURIComponent(ret);
  for(unicodeStr in hash_map){hexEscStr=hash_map[unicodeStr];ret=replacer(unicodeStr,hexEscStr,ret);}
  return ret.replace(/(\%([a-z0-9]{2}))/g, function (full, m1, m2) {return "%"+m2.toUpperCase();});
}



function listPDF(inID){
  var i=0;
  var intSplit=['',''];
  var intList=document.getElementById('PDF').value.split('|§|');
  for(i=0;document.getElementById('PDFlistings').rows.length>0;i++){document.getElementById('PDFlistings').deleteRow(0)}
  for(i=0;i<intList.length-1;i++){
    intSplit=intList[i].split('|');
    Insert1Cell('PDFlistings',1,'','<A HREF="javascript:listDel('+i+',\'PDF\',\'listPDF('+inID+')\');"><IMG SRC="/gfx/butt_delete.gif" BORDER="0"></A><IMG SRC="gfx/spacer.gif" WIDTH="2"><A HREF="javascript:listUp('+i+',\'PDF\',\'listPDF('+inID+')\');"><IMG SRC="/gfx/butt_up.gif" BORDER="0"></A><A HREF="javascript:listDown('+i+',\'PDF\',\'listPDF('+inID+')\');"><IMG SRC="/gfx/butt_down.gif" BORDER="0"></A><IMG SRC="/gfx/spacer.gif" WIDTH="8"><A HREF="javascript:sendfile(\'pdf/'+intSplit[1]+'\');">'+intSplit[0]+'</A>')
  }
  Insert1Cell('PDFlistings',1,'','<TABLE CELLSPACING=""0"" CELLPADDING=""0""><TR><TD><INPUT TYPE="text" NAME="newPDF" STYLE="width:398px;heigth:18px;"></TD><TD><IMG SRC="gfx/spacer.gif" WIDTH="2"></TD><TD><IFRAME SRC="adm_fileretr.asp?type='+inID+'&return=listPDF('+inID+')" WIDTH="200" HEIGHT="22" MARGINHEIGHT="0" MARGINWIDTH="0" FRAMEBORDER="0" SCROLLING="no"></IFRAME></TD></TR></TABLE>')
}

function liste(inID){
  var i=0;
  var nlst='';
  var liste=document.CompleteForm.motorer.value.split('|§|');
  if(document.CompleteForm.tmp.value!=''){
    tinyMCE.get('t_'+document.CompleteForm.tmp.value).setContent(tinyMCE.get('sidedata').getContent())
    liste[document.CompleteForm.tmp.value]=document.CompleteForm.motornavn.value;
    for(i=0;i<liste.length-1;i++){nlst+=liste[i]+'|§|'};
    document.CompleteForm.motorer.value=nlst;
  }
  if(liste.length>1){document.getElementById('editor').style.visibility='visible';}
  for(i=0;document.getElementById('motorliste').rows.length>0;i=0){document.getElementById('motorliste').deleteRow(0)}
  for(i=0;i<liste.length-1;i++){
    Insert1Cell('motorliste',1,'','<TABLE CELLSPACING="0" CELLPADDING="0"><TR><TD><DIV CLASS="selector_btn" STYLE="color:#6c242f;font-weight:bold;cursor:pointer;" ONCLICK="liste('+i+');">'+liste[i]+'</DIV></TD><TD>&nbsp;<IMG SRC="/gfx/butt_delete.gif" TITLE="SLETT oppføring" STYLE="cursor:pointer;" ONCLICK="liste_slett('+i+');">&nbsp;<IMG SRC="/gfx/butt_up.gif" TITLE="Flytt opp" STYLE="cursor:pointer;" ONCLICK="liste_opp('+i+');"><IMG SRC="/gfx/butt_down.gif" TITLE="Flytt ned" STYLE="cursor:pointer;" ONCLICK="liste_ned('+i+');"></TD></TR></TABLE>');
  }
  if(i<1){Insert1Cell('motorliste',1,'','<DIV STYLE="color:#6c242f;font-weight:bold;cursor:pointer;"" ONCLICK="document.CompleteForm.motorer.value+=\'|§|\';document.CompleteForm.motornavn.value=\'Ny oppføring\';liste('+i+');">- Ny oppføring -</DIV>')}
  if(i<15 && i>0){Insert1Cell('motorliste',1,'','<DIV STYLE="color:#6c242f;font-weight:bold;cursor:pointer;"" ONCLICK="document.CompleteForm.motorer.value+=\'Ny oppføring|§|\';liste('+i+');">- Ny oppføring -</DIV>')}
  if(liste.length>inID){
    document.CompleteForm.motornavn.value=liste[inID];
    tinyMCE.get('sidedata').setContent(tinyMCE.get('t_'+inID).getContent())
  }
  document.CompleteForm.tmp.value=inID;
}

function liste_opp(inID){
  var i=0;
  var tmp='';
  var nlst='';
  var oliste=document.CompleteForm.motorer.value.split('|§|');
  if(inID<1){
    alert('Kan ikke flytte opp.\nDette er den øverste');
  }else{
    liste(0);
    tmp=oliste[inID];
    oliste[inID]=oliste[(parseInt(inID)-1)];
    oliste[(parseInt(inID)-1)]=tmp;
    for(i=0;i<oliste.length-1;i++){nlst+=oliste[i]+'|§|'};
    document.CompleteForm.motorer.value=nlst;
    tmp=tinyMCE.get('t_'+inID).getContent();
    tinyMCE.get('t_'+inID).setContent(tinyMCE.get('t_'+(parseInt(inID)-1)).getContent());
    tinyMCE.get('t_'+(parseInt(inID)-1)).setContent(tmp);
    tmp=document.CompleteForm.tmp.value
    document.CompleteForm.tmp.value='';
    liste(inID);
  }
}

function liste_ned(inID){
  var i=0;
  var tmp='';
  var nlst='';
  var oliste=document.CompleteForm.motorer.value.split('|§|');
  if(inID>oliste.length-3){
    alert('Kan ikke flytte ned.\nDette er den nederste');
  }else{
    liste(0);
    tmp=oliste[inID];
    oliste[inID]=oliste[(parseInt(inID)+1)];
    oliste[(parseInt(inID)+1)]=tmp;
    for(i=0;i<oliste.length-1;i++){nlst+=oliste[i]+'|§|'};
    document.CompleteForm.motorer.value=nlst;
    tmp=tinyMCE.get('t_'+inID).getContent();
    tinyMCE.get('t_'+inID).setContent(tinyMCE.get('t_'+(parseInt(inID)+1)).getContent());
    tinyMCE.get('t_'+(parseInt(inID)+1)).setContent(tmp);
    tmp=document.CompleteForm.tmp.value
    document.CompleteForm.tmp.value='';
    liste(inID);
  }
}

function liste_slett(inID){
  var i=0;
  var nlst='';
  var oliste=document.CompleteForm.motorer.value.split('|§|');
  if(confirm('Dette vil SLETTE oppføringen')){
    // ------- First of all : save the active form -------
    tinyMCE.get('t_'+document.CompleteForm.tmp.value).setContent(tinyMCE.get('sidedata').getContent())
    oliste[document.CompleteForm.tmp.value]=document.CompleteForm.motornavn.value;
    // ------- Delete from listing ---------
    for(i=0;i<oliste.length-1;i++){if(i!=inID){nlst+=oliste[i]+'|§|'}}
    document.CompleteForm.motorer.value=nlst;
    // ------- Delete from forms ---------
    for(i=inID;i<oliste.length-1;i++){tinyMCE.get('t_'+i).setContent(tinyMCE.get('t_'+(parseInt(i)+1)).getContent());}
    tinyMCE.get('t_'+i).setContent('');
    // ------- Prepare to refresh, and set object 0 as active ---------
    document.CompleteForm.tmp.value='';
    liste(0);
  }
}

function listPDFsingle(inID){
  var i=0;
  var intSplit=['',''];
  var intList=document.getElementById('PDF').value.split('|§|');
//alert(document.getElementById('PDF').value)
  for(i=0;document.getElementById('PDFlistings').rows.length>0;i++){document.getElementById('PDFlistings').deleteRow(0)}
  for(i=0;i<intList.length-1;i++){
    intSplit=intList[i].split('|');
    Insert1Cell('PDFlistings',1,'','<A HREF="javascript:DelPDFSingle('+i+','+inID+',\'PDF\');"><IMG SRC="/gfx/butt_delete.gif" BORDER="0"></A><IMG SRC="/gfx/spacer.gif" WIDTH="8"><A HREF="javascript:sendfile(\'/pdf/'+intSplit[1]+'\');">'+intSplit[0]+'</A>');
  }
  Insert1Cell('PDFlistings',1,'','<TABLE CELLSPACING=""0"" CELLPADDING=""0""><TR><TD><IFRAME SRC="adm_fileretr.asp?type='+inID+'&return=listPDFsingle('+inID+')" WIDTH="500" HEIGHT="22" MARGINHEIGHT="0" MARGINWIDTH="0" FRAMEBORDER="0" SCROLLING="no"></IFRAME></TD></TR></TABLE>')
}

function DelPDFSingle(inIndex,inID,inField){
  if(confirm('Dette vil SLETTE PDF-vedlegget')){
    document.getElementById(inField).value='';
    listPDFsingle(inID);
  }
}

function listPIC(inID){
  var i=0;
  var intSplit=['',''];
  var intList=document.getElementById('PIC').value.split('|§|');
  for(i=0;document.getElementById('PIClistings').rows.length>0;i++){document.getElementById('PIClistings').deleteRow(0)}
  for(i=0;i<intList.length-1;i++){
    intSplit=intList[i].split('|');
    Insert1Cell('PIClistings',1,'','<A HREF="javascript:listDel('+i+',\'PIC\',\'listPIC('+inID+')\');"><IMG SRC="/gfx/butt_delete.gif" BORDER="0"></A><IMG SRC="/gfx/spacer.gif" WIDTH="2"><A HREF="javascript:listUp('+i+',\'PIC\',\'listPIC('+inID+')\');"><IMG SRC="/gfx/butt_up.gif" BORDER="0"></A><A HREF="javascript:listDown('+i+',\'PIC\',\'listPIC('+inID+')\');"><IMG SRC="/gfx/butt_down.gif" BORDER="0"></A><IMG SRC="/gfx/spacer.gif" WIDTH="8"><IMG SRC="/images/'+intSplit[0]+'">')
    Insert1Cell('PIClistings',1,'','<IMG SRC="gfx/spacer.gif" HEIGHT="5">')
  }
  Insert1Cell('PIClistings',1,'','<TABLE CELLSPACING=""0"" CELLPADDING=""0""><TR><TD><IFRAME SRC="adm_fileretr.asp?type='+inID+'&return=listPIC('+inID+')" WIDTH="500" HEIGHT="22" MARGINHEIGHT="0" MARGINWIDTH="0" FRAMEBORDER="0" SCROLLING="no"></IFRAME></TD></TR></TABLE>')
}

function listDel(inID,inField,inReturn){
  if(confirm('Dette vil fjerne linken')){
    var i=0;
    var r='';
    var intList=document.getElementById(inField).value.split('|§|');
    for(i=0;i<intList.length-1;i++){if(i!=inID){r+=intList[i]+'|§|'}}
    document.getElementById(inField).value=r;
    setTimeout(inReturn,50);
  }
}

function listUp(inID,inField,inReturn){
  if(inID==0){
    alert('Kan ikke flytte opp.\nDette er den øverste');
  }else{
    var i=0;
    var r='';
    var intList=document.getElementById(inField).value.split('|§|');
    r=intList[inID]
    intList[inID]=intList[parseInt(inID)-1];
    intList[parseInt(inID)-1]=r;
    r=''
    for(i=0;i<intList.length-1;i++){r+=intList[i]+'|§|'}
    document.getElementById(inField).value=r;
    setTimeout(inReturn,1);
  }
}

function listDown(inID,inField,inReturn){
  var intList=document.getElementById(inField).value.split('|§|');
  if(inID==intList.length-2){
    alert('Kan ikke flytte ned.\nDette er den nederste');
  }else{
    var i=0;
    var r='';
    r=intList[parseInt(inID)+1]
    intList[parseInt(inID)+1]=intList[inID];
    intList[inID]=r;
    r=''
    for(i=0;i<intList.length-1;i++){r+=intList[i]+'|§|'}
    document.getElementById(inField).value=r;
    setTimeout(inReturn,1);
  }
}

