// Copyright 2006 Harald Becker - www.Telefon-Sparbuch.de

var isFirefox = (window.pkcs11&&window.XML) ? 1 : 0
var wdayNames = new Array("Sonntag", "Montag", "Dienstag", "Mittwoch","Donnerstag", "Freitag", "Samstag")
var cookieLifeTime=60 * 60 * 24 * 365 * 1000 * 2
var cookieName="TSBcallings"
var cookieKeys=new Array("dialPort","entriesPerPage", "searchVia")
dialPort = cookieGetKey("dialPort", dialPort)
var entriesPerPage = cookieGetKey("entriesPerPage", 30)
var searchVia = cookieGetKey("searchVia", 0)
var tableData = new Array()
var tableSum = new Array()
dataDate = new Date()
var previousDialed = -1
var questionClear="Alle Einträge in der Anrufliste werden jetzt gelöscht."
var startPage = 1
var currentPage = 1
var maxPagesPerIndex = 5
var colNrTyp = 0
var colNrDate = 1
var colNrCbC = 2
var colNrRufnummer = 3
var colNrNebenstelle=4
var colNrMSN = 5
var colNrRoute=6
var colNrDauer = 7
var sortHeadline = ""
var defaultColSortNr = 1
var defaultSortDir = "down"
var cryptNumber=0
var cryptMSN=0
var showCounter = 1
var colHeadlines = new Array(
"Typ",
"Zeitpunkt",
"Call<br>by Call",
"Rufnummer",
"Neben-<br>stelle",
"MSN",
"Leit-<br>ung",
"Dauer<br><small>hh:mm:ss</small>"
)
var dataFields=colHeadlines.length
var colsWidth = new Array(
35,120,50,140,50,60,50,50
)
colsHeadlineWidth = 35
var colSortTypes = new Array(
"num","char","num","char","num","num","num","num"
)
var colVisible = new Array(
1,1,1,1,1,1,1,1
)
if (colVisible.length != colHeadlines.length) alert ("colVisible Einträge falsch")
var Select_entriesPerPage = new Array(10,20,30,40,50,60,100,150,200,300)
var searchCall= new Array(
"Das Örtliche", "http://www.dasoertliche.de/?form_name=search_inv&ph=",
"Das Telefonbuch", "http://dastelefonbuch.de/?sp=55&aktion=23&ort=&cifav=0&s=a10000&stype=S&la=de&cmd=search&ort_ok=0&vert_ok=0&x=31&y=9&kw=",
"11880", "http://www.11880.com/Suche/index.cfm?fuseaction=Suche.rueckwaertssucheresult&init=true&tel=",
"GoYellow", "http://www.goyellow.de/IDA2?IDAERROR=&QRY=all&RNG=lequ&CTRY=ger&LANG=de&PAGE=simpleSearch&LIP=simpleSearch&ACTION=nationWideSearch&STP=C&REQ=20&ZCD=&LOC=&MDN=",
"Inverssuche", "http://www.inverssuche.de/search_inverse.aspx?__EVENTTARGET=cmdSearch&cmdSearch=Suchen&txtNumber=",
"klickTel (Anmeldung)", "http://telefonauskunft.klicktel.de/inverseSearch.php?newSearch=1&submit=Suchen&vollstaendig="
)
if (callingsAVM.length > 0) {
if (iDialNumber != "") {
if (iDialPort >= 50) iDialPort=4; else iDialPort -= 1
tableData.push(7,dateStr(dataDate,1),"",iDialNumber,iDialPort,"","","")
}
var cbcSearch
if (amt == "0") {
cbcSearch = /^0(0100\d\d|010\d\d|090050|09001035|09001051)(.+)/;
} else {
cbcSearch = /^(0100\d\d|010\d\d|090050|09001035|09001051)(.+)/;
}
var lines=sipstr.split("^")
var sip = new Array()
for (var i=0; i < lines.length; i++) {
var entries=lines[i].split(";")
var pos=entries[0].replace(/sip(.*)/, "$1")
var nr=entries[1]
sip[pos]=nr
}
lines=callingsAVM.split("^")
for (var i=0; i < lines.length; i++) {
var entries=lines[i].split(";")
var typ = entries[0]
if (typ == 1) typ = 2
else if (typ == 2) typ = 3
else if (typ == 3) typ = 1
else typ = 0
if (typ > 0) {

var date = entries[1].replace(/^(\d\d)\.(\d\d)\.(\d\d)/, "$3.$2.$1")

var rufnummer = entries[2]
var cbc = ""
var result = cbcSearch.exec(rufnummer);
if (result && result.length == 3) {
cbc = result[1]
rufnummer = result[2]
}
var nebenstelle = entries[3]
if (nebenstelle == 36) nebenstelle = 5

var msn = entries[5]
var route = entries[6]
if (route == "0") {
if (rufnummer.match(/^[1-9]/)) {
if (!rufnummer.match(/^49[1-9]/)) {
rufnummer = vorwahl+""+rufnummer
}
}
if (msn == "") msn = ""
} else if (msn == "") msn = sip[0]; else msn = sip[msn]

var t = entries[4].split(":")
var dauer = t[0]*3600+t[1]*60
tableData.push(typ,date,cbc,rufnummer,nebenstelle,msn,route,dauer)
}
}
} else {
var lines=callings.split("^")
for (var i=0; i < lines.length; i++) {
var entries=lines[i].split(";")
if (entries.length == dataFields)
for (var e=0; e < dataFields; e++)
tableData.push(entries[e])
}
}
var cols=0
for (var i=0; i<colVisible.length; i++)
if (colVisible[i] == "1") ++cols
var ColSortNr1 = showCounter
var ColSortNr2 = cols
cols=ColSortNr1+ColSortNr2
var tableDataSorted = new Array(tableData.length)
var rows = tableData.length / dataFields
var iconUp = "<img src=\"/htmltsb/up.gif\" width=\"16\" height=\"17\" border=\"0\" alt=\"Auf \">"
var iconDown = "<img src=\"/htmltsb/down.gif\" width=\"16\" height=\"17\" border=\"0\" alt=\"Ab \">"
var iconUpSorted = "<img src=\"/htmltsb/up_on.gif\" width=\"16\" height=\"17\" border=\"0\" alt=\"AUF \">"
var iconDownSorted = "<img src=\"/htmltsb/down_on.gif\" width=\"16\" height=\"17\" border=\"0\" alt=\"AB \">"
var colImg_Typ = new Array()
colImg_Typ[1] = "<img src=\"/htmltsb/Callout.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"OUT\">"
colImg_Typ[2] = "<img src=\"/htmltsb/Callin.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"IN\">"
colImg_Typ[3] = "<img src=\"/htmltsb/Callinfailed.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"MISS\">"
colImg_Typ[4] = "<img src=\"/htmltsb/Callinfailed.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"MISS4\">4"
colImg_Typ[5] = "<img src=\"/htmltsb/Callinfailed.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"MISS5\">5"
colImg_Typ[6] = "<img src=\"/htmltsb/Callinfailed.gif\" width=\"16\" height=\"16\" border=\"0\" alt=\"MISS6\">6"
colImg_Typ[7] = "<img src=\"/htmltsb/tel.gif\" width=\"17\" height=\"17\" alt=\"DIAL\">"
var showEntriesOf_Typ = new Array(1,1,1,1,1,1)
var rowColor = new Array()
rowColor[1] = "altO"
rowColor[2] = "altI"
rowColor[3] = "altA"
rowColor[4] = "altP"
rowColor[5] = "altP"
rowColor[6] = "altP"
rowColor[7] = "altP"
var nameOfNebenstelle = new Array(
"Fon &nbsp;1",
"Fon &nbsp;2",
"Fon &nbsp;3",
"Durchw",
"Fon S0",
"Dat S0"
)
calcSum()
function calcSum(){
for (i = 0; i < dataFields; ++i) {
tableSum[i] = new Array()
tableSum[colNrTyp] = new Array()
for (typ=0; typ < 7; ++typ) tableSum[colNrTyp][typ] = 0
tableSum[colNrNebenstelle] = new Array()
tableSum[colNrDauer] = new Array()
for (typ=0; typ < colImg_Typ.length; ++typ) {
tableSum[colNrNebenstelle][typ] = new Array()
tableSum[colNrDauer][typ] = new Array()
for (nebenstelle=0; nebenstelle < nameOfNebenstelle.length; ++nebenstelle){
tableSum[colNrNebenstelle][typ][nebenstelle]=0
tableSum[colNrDauer][typ][nebenstelle] = 0
}
}
}
for (i = 0; i < rows; ++i) {
var z = i * dataFields
var typ = tableData[z + colNrTyp]
++tableSum[colNrTyp][typ]
var nebenstelle = tableData[z + colNrNebenstelle]
tableSum[colNrNebenstelle][typ][nebenstelle] += 1
var dauer = tableData[z + colNrDauer]
if (dauer > 0) {
tableSum[colNrDauer][typ][nebenstelle] += parseInt(dauer)
}
}
}
function makeSortHeadline(number,direction) {
sortHeadline = "<tr class=\"alt2\">"
if (showCounter)
sortHeadline += "<td></td>"
for (var j = 0; j < dataFields; ++j) {
if (colVisible[j] == 1) {
sortHeadline += "<td nowrap>"
if (direction == "up" && j == number) {
sortHeadline += "<a href=\"javascript:sortCol(" + j + ",'" + colSortTypes[j] + "','down')\">" + iconDown + "</a>"
sortHeadline += iconUpSorted
} else if (direction == "down" && j == number) {
sortHeadline += iconDownSorted
sortHeadline += "<a href=\"javascript:sortCol(" + j + ",'" + colSortTypes[j] + "','up')\">" + iconUp + "</a>"
} else {
sortHeadline += "<a href=\"javascript:sortCol(" + j + ",'" + colSortTypes[j] + "','down')\">" + iconDown + "</a>"
sortHeadline += "<a href=\"javascript:sortCol(" + j + ",'" + colSortTypes[j] + "','up')\">" + iconUp + "</a>"
}
sortHeadline += "</td>"
}
}
sortHeadline += "</tr>"
}
function sortCol(number,type,direction) {
makeSortColTableData(number,type,direction)
makeSortHeadline(number,direction)
printTableData(tableDataSorted, entriesPerPage, currentPage)
}
function makeSortColTableData(sortNumber1,type,direction) {
var colsData = new Array()
var comparativeData = new Array()
var sortIndex = new Array()
var sortNumber2 = ColSortNr1
if (sortNumber1 == sortNumber2)
sortNumber2 = ColSortNr2
for(var i = 0; i < rows; ++i) {
var z = i * dataFields
colsData[i] = comparativeData[i] = tableData[z + sortNumber1] +"Z"+ tableData[z + sortNumber2] +"Z"+ i
}
if (type == "char") colsData.sort() // sortByString
else if (type == "num") colsData.sort(sortByNumber)
if (direction == "down") colsData.reverse()
for (i = 0; i < rows; ++i) {
for (var j = 0; j < rows; ++j) {
if (colsData[i] == comparativeData[j]) {
sortIndex[i] = j
}
}
}
for (i = 0; i < rows; ++i) {
var z = i * dataFields
var zS= sortIndex[i] * dataFields
for (j = 0; j < dataFields; ++j) {
tableDataSorted[z + j] = tableData[zS + j]
}
}
}
function pageIndex(rows, entriesPerPage, currentPage) {
var pageIndex = ""
var tdPages = 15
if (rows < 1) rows = 1
var pages = Math.ceil(rows / entriesPerPage)
pageIndex += "<div class=\"indexNav\" align=\"right\">"
pageIndex += "<table class=\"tborder1\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\">"
pageIndex += "<tbody><tr>"
var showCurrentPage = currentPage
pageIndex += "<td width=\"60\" class=\"index\" style=\"font-weight: normal;\">"+currentPage+" von "+pages+"</td>"
var IndexStart = currentPage
IndexStart = IndexStart - Math.floor(maxPagesPerIndex/2)
if (IndexStart < 1) IndexStart = 1
IndexStop = IndexStart+maxPagesPerIndex-1
if (IndexStop > pages) {
IndexStop = pages
IndexStart = IndexStop-maxPagesPerIndex+1
}
if (IndexStart < 1) IndexStart = 1
if (pages > maxPagesPerIndex) {
var i = 1
var from = (i-1)*entriesPerPage+1
var till = (i-1)*entriesPerPage+entriesPerPage
if (currentPage > 1) {
pageIndex += "<td class=\"alt1\"><a class=\"smallfont\" href=\"javascript:showTable("+entriesPerPage+","+i+");\" title=\"Erste Seite - Ergebnis "+from+" bis "+till+" von "+rows+"\"><strong>«</strong></a></td>"
} else if (pages > maxPagesPerIndex) {
pageIndex += "<td class=\"alt2\"><span class=\"smallfont\" title=\"Erste Seite - Ergebnis "+from+" bis "+till+" von "+rows+"\"><strong>«</strong></td>"
}
}
var i = currentPage-1
if (i < 1) i = 1
var from = (i-1)*entriesPerPage+1
var till = (i-1)*entriesPerPage+entriesPerPage
if (currentPage > 1) {
pageIndex += "<td class=\"alt1\"><a class=\"smallfont\" href=\"javascript:showTable("+entriesPerPage+","+i+");\" title=\"Zeige Ergebnis "+from+" bis "+till+" von "+rows+"\">&lt;</a></td>"
} else {
pageIndex += "<td class=\"alt2\"><span class=\"smallfont\" title=\"Zeige Ergebnis "+from+" bis "+till+" von "+rows+"\">&lt;</span></td>"
}
for (var i=IndexStart; i<=IndexStop; ++i) {
var from = (i-1)*entriesPerPage+1
var till = (i-1)*entriesPerPage+entriesPerPage
if (till > rows) till=rows
if (i == currentPage) {
pageIndex += "<td width=\""+tdPages+"\" class=\"alt2\"><span class=\"smallfont\" title=\"Zeige Ergebnis "+from+" bis "+till+" von "+rows+"\"><strong>"+currentPage+"</strong></span></td>"
} else {
pageIndex += "<td width=\""+tdPages+"\" class=\"alt1\"><a class=\"smallfont\" href=\"javascript:showTable("+entriesPerPage+","+i+");\" title=\"Zeige Ergebnis "+from+" bis "+till+" von "+rows+"\">"+i+"</a></td>"
}
}
var i = currentPage+1
var from = (i-1)*entriesPerPage+1
var till = (i-1)*entriesPerPage+entriesPerPage
if (currentPage < pages) {
pageIndex += "<td class=\"alt1\"><a class=\"smallfont\" href=\"javascript:showTable("+entriesPerPage+","+i+");\" title=\"Zeige Ergebnis "+from+" bis "+till+" von "+rows+"\">&gt;</a></td>"
} else {
pageIndex += "<td class=\"alt2\"><span class=\"smallfont\" title=\"Zeige Ergebnis "+from+" bis "+till+" von "+rows+"\">&gt;</span></td>"
}
if (pages > maxPagesPerIndex) {
var i = pages
var from = (i-1)*entriesPerPage+1
var till = (i-1)*entriesPerPage+entriesPerPage
if (currentPage < pages) {
pageIndex += "<td class=\"alt1\"><a class=\"smallfont\" href=\"javascript:showTable("+entriesPerPage+","+i+");\" title=\"Letzte Seite - Ergebnis "+from+" bis "+till+" von "+rows+"\"><strong>»</strong></a></td>"
} else {
pageIndex += "<td class=\"alt2\"><span class=\"smallfont\" title=\"Letzte Seite - Ergebnis "+from+" bis "+till+" von "+rows+"\"><strong>»</strong></td>"
}
}
pageIndex += "</tr>"
pageIndex += "</tbody></table>"
pageIndex += "</div>"
return pageIndex
}
function showTable(entriesPerPageSET, currentPageSET) {
entriesPerPage=entriesPerPageSET
currentPage=currentPageSET
printTableData(tableDataSorted, entriesPerPage, currentPage)
}
function tableHeader(){
var headline = "<tr class=\"alt2\">"
if (showCounter)
headline += "<th width=\""+colsHeadlineWidth+"\"><img src=\"/htmltsb/dy.gif\" width=\""+ colsHeadlineWidth +"\" height=\"1\" border=\"0\"></th>"
for (var j = 0; j < dataFields; ++j) {
if (colVisible[j] == 1) {
headline += "<th width=\""+ colsWidth[j] +"\" nowrap>" + colHeadlines[j]
headline += "<br><img src=\"/htmltsb/dy.gif\" width=\""+ colsWidth[j] +"\" height=\"1\" border=\"0\">"
headline += "</th>"
}
}
headline += "</tr>"
return headline
}
function __sec(sec){
if (sec > 0) {
var min = Math.floor(sec / 60)
var hour= Math.floor(min / 60)
min -= hour*60
sec = sec - min*60 - hour*3600
if (hour < 10)
if (hour == 0)
hour = '--'
else
hour="0"+hour
if (min < 10)
if (min == 0 && hour == "--")
min = '--'
else
min ="0"+min
if (sec < 10)
if (sec == 0 && min == "--")
sec = '--'
else
sec="0"+sec
} else {
return ""
}
return hour +":"+ min +":"+ sec
}
function printTableData(Array, entriesPerPage, currentPage) {
var infoMenu = "<div class=\"indexMenu\" align=\"left\"><table width=\"100%\" class=\"tborder1\" cellpadding=\"3\" cellspacing=\"1\" border=\"0\"><tr>"
infoMenu += "<td class=\"index\"><a href=\"?saveCallings"+ sid +"\">Speichern</a></td>"
infoMenu += "<td class=\"index\"><a href=\"?deleteCallings"+ sid +"\" onclick=\"if (!confirm(questionClear)) return false;\">Löschen</a></td>"
var infoIndex = pageIndex(rows, entriesPerPage, currentPage)
var infoDial = "<select name=\"dialPort\" onchange=\"activeDialPort(1)\">"
for (var i=0;i<portNames.length;++i) {
if (i != 3 && i != 5) {
var portNr=i+1
if (portNr == 5) {
portNr = 50
}
var selected=""
if (portNr == dialPort) selected=" selected"
infoDial += "<option value=\""+ portNr +"\""+ selected +">"+ portNames[i] +"</option>"
if (portNr == 50) {
for (var p=0; p < portMSNNr.length; p++) {
var pos=(portNr+p+1)
if (portMSNNr[p] != "") {
var selected=""
if (pos == dialPort) selected=" selected"
infoDial += "<option value=\""+ pos +"\""+ selected +">- "+ portMSNNames[p] +"</option>"
}
}
}
}
}
infoDial += "</select>"
var infoSearchVia = "Suche via:<select name=\"searchVia\" onchange=\"setSearchVia(1)\">"
for (i=0;i<searchCall.length;i+=2) {
var selected=""
if (i == searchVia) selected=" selected"
infoSearchVia += "<option value=\""+ i +"\""+ selected +">"+ searchCall[i] +"</option>"
}
infoSearchVia += "</select>"
var infoDialNumber ="<input type=\"text\" name=\"dialNumber\" value=\"\" size=\"25\"> <img src=\"/htmltsb/Callout.gif\" width=\"16\" height=\"16\" border=\"0\" style=\"padding-bottom:3px;vertical-align:bottom\" onclick=\"dial(0,document.TSB.dialNumber.value, 'Manuell',1);false\" alt=\"Dial\"><img name=\"Manuell\" src=\"/htmltsb/dy.gif\" width=\"10\" height=\"10\" border=\"0\" alt=\"\">"
var infoRows = "<select name=\"entriesPerPage\" onchange=\"entriesPerPageUpdate()\">"

for (i=0;i<Select_entriesPerPage.length;++i) {
var selected=""
if (Select_entriesPerPage[i] == entriesPerPage) selected=" selected"
infoRows += "<option value=\""+ Select_entriesPerPage[i] +"\""+ selected +">"+ Select_entriesPerPage[i] +"</option>"
}
infoRows += "</select>"
infoMenu += "<td class=\"index\"><img src=\"/htmltsb/rows.gif\" style=\"padding-bottom:3px;vertical-align:bottom\" width=\"17\" height=\"17\" alt=\"Zeilen\"> "+ infoRows +"</td>"
infoMenu += "<td class=\"index\">"+ infoSearchVia +"</td>"
infoMenu += "<td class=\"index\" width=90%>&nbsp;</td>"
infoMenu += "</tr></table></div>"
var tableStr = "<form name=\"TSB\" onsubmit=\"return false\">"
tableStr += "<h3><a href=\"http://www.telefonsparbuch.de\" style=\"text-decoration:none\" target=_blank>Telefon-Sparbuch</a> LCR: Verbindungsübersicht</h3>"
if (errorMsg) {
tableStr += errorMsg
}
tableStr += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"padding:0px\">"
tableStr += "<tr><td colspan=\"2\" style=\"text-align:right; font: bold 11px verdana, tahoma, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;\"><a href=\"?showCallings"+sid+"\">Anrufliste</a> <span class=\"smallfont\">("+ rows +" Einträge)</span></td></tr>"
tableStr += "<tr><td style=\"text-align:left\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"padding:0px\"><tr>"
tableStr += "<td><img src=\"/htmltsb/tel.gif\" style=\"padding-bottom:3px;vertical-align:bottom\" width=\"17\" height=\"17\" alt=\"Port\"> "+ infoDial +"</td>"
tableStr += "<td>"+ infoDialNumber +"</td>"
tableStr += "</tr></table></td>"
tableStr += "<td valign=\"bottom\">"+ infoIndex +"</td></tr>"
tableStr += "<tr><td colspan=\"2\">"
tableStr += "<div class=\"indexNav\" align=\"left\">"
tableStr += "<table class=\"tborder2\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\">"
tableStr += "<tbody>"
tableStr += tableHeader()
tableStr += sortHeadline
var searchHref=searchCall[parseInt(searchVia)+1]
entriesShown = 0
var from = startPage * entriesPerPage * (currentPage-1)
var till = from+entriesPerPage
if (till > rows) till = rows
for (var i = from; i < till; ++i) {
var z = i * dataFields
tableStr += "<tr class=\""+rowColor[Array[z+colNrTyp]]+"\">"
if (showCounter) {
var o = i+1
if (o < 10) o = "&nbsp;"+o
tableStr += "<td>" + o + ".</td>"
}
for (var j = 0; j < dataFields; ++j){
if (colVisible[j] == 1) {
var val = Array[z+j]
if (j == colNrDate) {
var date = val.replace(/^(\d\d)\.(\d\d)\.(\d\d)/, "$3.$2.$1")
tableStr += "<td nowrap>" + date + "</td>"
} else if (j == colNrTyp) {
tableStr += "<td>" + colImg_Typ[ val ] + "</td>"
} else if (j == colNrDauer) {
if (val < 0) {
var currentdate = new Date()
var time = Array[z+1].split(" ")
var d = time[0].split("\.")
var t = time[1].split(":")
d[2] = 20+d[2]
var startdate = new Date(d[1]+" "+d[0]+", "+d[2]+" "+t[0]+":"+t[1]+":"+Math.abs(val))
var difference = currentdate.getTime() - startdate.getTime()
val = Math.floor(difference/1000)
}
tableStr += "<td nowrap>"+__sec(val)+"</td>"
} else if (j == colNrNebenstelle) {
if (val == "")
tableStr += "<td></td>"
else
tableStr += "<td nowrap>" + nameOfNebenstelle[ val ] + "</td>"
} else if (j == colNrRufnummer) {
if (val == "") {
tableStr += "<td class=\"tdL\" nowrap><img src=\"/htmltsb/dy.gif\" width=\"10\" height=\"10\" border=\"0\" align=\"right\">unbekannt</td>"
} else {
tableStr += "<td class=\"tdL\" nowrap>"
var searchnr = "" 
if (val.match(/^(00|\*)/)) {
if (val.match(/^0049/)) {
searchnr = val.replace(/^0049(.+)/, "0$1");
}
} else {
searchnr = val
}
if (searchnr == "") {
tableStr += "<img name=\"I"+z+"\" src=\"/htmltsb/dy.gif\" width=\"10\" height=\"10\" border=\"0\" align=\"right\">"
} else {
searchnummer = searchnr.replace(/^([1-9])/, vorwahl+"$1");
tableStr += "<a href=\""+ searchHref +""+ searchnummer +"\" target=_blank><img name=\"I"+z+"\" src=\"/htmltsb/i.gif\" width=\"10\" height=\"10\" border=\"0\" align=\"right\" alt=\"i\"></a>"
}
var dial=val
if (cryptNumber) {
for (var x=0; x<cryptNumber; x++) {
val = val.replace(/\d(x*)$/, "$1x")
}
}
tableStr += "<a href=\"javascript:dial("+ z +", '"+ dial +"','')\">"+ val +"</a>"
tableStr += "</td>"
}
} else if (j == colNrMSN) {
if (val == "") {
tableStr += "<td>-</td>"
} else if (cryptMSN) {
for (var x=0; x<cryptMSN; x++) {
val = val.replace(/\d(x*)$/, "$1x")
}
tableStr += "<td nowrap>" + val + "</td>"
} else {
tableStr += "<td nowrap>" + val + "</td>"
}
} else if (j == colNrRoute) {
if (val == "") 
tableStr += "<td class=\"small\"></td>"
else if (val == "0") 
tableStr += "<td class=\"small\">Festnetz</td>"
else 
tableStr += "<td class=\"smallH\">Internet</td>"
} else {
tableStr += "<td nowrap>" + val + "</td>"
}
}
}
tableStr += "</tr>"
}
var first=0
if (tableSum[colNrTyp][3] > 0) {
var colspan=cols-3
first++
tableStr += "<tr class=\"altG\">"
tableStr += "<td colspan=\""+ colspan +"\">Gesamt:</td><td></td><td>"+ tableSum[colNrTyp][3] +"*"+ colImg_Typ[3] +"</td><td></td></tr>"
}
var colspan=cols-3
for (var nebenstelle=0; nebenstelle < nameOfNebenstelle.length; ++nebenstelle) {
for (var typ=1; typ < 3; ++typ) {
if (tableSum[colNrNebenstelle][typ][nebenstelle] > 0) {
tableStr += "<tr class=\"altG\">"
if (first++ == 0)
tableStr += "<td colspan=\""+ colspan +"\">Gesamt:</td>"
else
tableStr += "<td colspan=\""+ colspan +"\"></td>"
tableStr += "<td>"+ nameOfNebenstelle[nebenstelle] + "</td><td>"+ tableSum[colNrNebenstelle][typ][nebenstelle] +"*"+ colImg_Typ[typ] +"</td><td>"+ __sec(tableSum[colNrDauer][typ][nebenstelle],1) +"</td></tr>"
}
}
}
tableStr += "<tr><td colspan=\""+ cols +"\">"+ infoMenu +"</td></tr>"
tableStr += "</tbody>"
tableStr += "</table></div>"
tableStr += "</td></tr>"
tableStr += "<tr><td style=\"text-align:left\"><span class=\"smallfont\">Ausgabe erstellt am "+dateStr(dataDate)+"</p></td><td valign=top>"+ infoIndex +"</td></tr>"
tableStr += "</table>"
tableStr += "</form>"
tableStr += "<p><u>Legende:</u></p><p>Die Anrufliste erfasst alle Telefonate und eingehende Anrufe in Abwesenheit.</p><p><img src=\"/htmltsb/Callout.gif\" alt=\"OUT\" border=\"0\" height=\"16\" width=\"16\"> ausgehende Anrufe <img src=\"/htmltsb/Callin.gif\" alt=\"IN\" border=\"0\" height=\"16\" width=\"16\"> eingehende Anrufe <img src=\"/htmltsb/Callinfailed.gif\" alt=\"MISS\" border=\"0\" height=\"16\" width=\"16\"> eingehende Anrufe in Abwesenheit</p>"
tableStr += "<p><img src=\"/htmltsb/tel.gif\" width=\"17\" height=\"17\" alt=\"Port\"> Rufwahl an gewählte Nebenstelle vermitteln. <input type=\"text\" size=\"3\" disabled> <img src=\"/htmltsb/Callout.gif\" width=\"16\" height=\"16\" border=\"0\" style=\"padding-bottom:3px;vertical-align:bottom\" alt=\"Dial\"> Manuelle Rufwahl</p>"
tableStr += "<p><img src=\"/htmltsb/rows.gif\" width=\"17\" height=\"17\" alt=\"Zeilen\"> Zahl der Zeilen pro Ausgabeseite <img src=\"/htmltsb/i.gif\" width=\"10\" height=\"10\" alt=\"i\"> Websuche der Rufnummer</p>"
tableStr += "<form action=\"index.html\" name=\"Callings\" method=\"POST\"><input type=\"hidden\" name=\"action\" value=\"dial\"><input type=\"hidden\" name=\"param\" value=\"\"><input type=\"hidden\" name=\"sid\" value=\""+sessionID+"\"></form>"
if (document.getElementById)
document.getElementById("tableData").innerHTML = tableStr
else if(document.all)
document.all.tableData.innerHTML = tableStr
else if(document.layers) {
document.tableData.document.open()
document.tableData.document.write(tableStr)
document.tableData.document.close()
}
}
function sortByNumber(a,b){
A = a.split("Z")
B = b.split("Z")
a = A[0]
b = B[0]
return (a==b) ? ( (A[1]==B[1])?0:(A[1]>B[1]?1:-1) ) : (a-b)
}
function sortByString(a, b) {
return(a==b)?0:(a>b)?1:-1
}
function optionsCallings(){
alert("Noch nicht implementiert!")
}
function entriesPerPageUpdate(){
var sel = document.TSB.entriesPerPage
entriesPerPage=sel.options[sel.selectedIndex].value
cookieWrite()
currentPage=1
printTableData(tableDataSorted, entriesPerPage, currentPage)
return
}
function setSearchVia(update){
var sel = document.TSB.searchVia
searchVia=sel.options[sel.selectedIndex].value
if (update == 1){
cookieWrite()
}
showTable(entriesPerPage, currentPage)
return 1
}
function activeDialPort(update){
var sel = document.TSB.dialPort
dialPort=sel.options[sel.selectedIndex].value
if (update == 1){
cookieWrite()
}
return 1
}
function dial(pos, dialNr, imageID, fromForm){
if (fromForm) {
if (dialNr.match(/^x\d+(y\d+)?$/)) {
cryptNumber=dialNr.replace(/x(\d+).*/g, "$1")
cryptMSN=0
if (dialNr.match(/y\d+/)) {
cryptMSN=dialNr.replace(/x\d+y(\d+).*/g, "$1")
}
showTable(entriesPerPage, currentPage)
return
} else {
if (cryptNumber || cryptMSN) {
cryptNumber=0
cryptMSN=0
showTable(entriesPerPage, currentPage)
}
}
dialNr = dialNr.replace(/[\(\[\{]+/g, '(')
dialNr = dialNr.replace(/[\)\]\}]+/g, ')')
dialNr = dialNr.replace(/[^0-9\+\(\)\*\#]+/g, '')
if (! dialNr.match(/^[\*\#]+/)) {
dialNr = dialNr.replace(/[\*\#]+/g, '')
}
dialNr = dialNr.replace(/^\++/, '00')
var intl = dialNr.match(/^00/)
if (dialNr.match(/^[1-9]/) && dialNr.match(/\(\d+\)/)) {
intl = 1
dialNr = "00"+dialNr
}
if (intl) {
dialNr = dialNr.replace(/^000+/, '00')
if (dialNr.match(/^0049/)) {
dialNr = dialNr.replace(/^0049/, '')
dialNr = dialNr.replace(/\((\d+)\)/, "$1")
} else {
dialNr = dialNr.replace(/\(\d+\)/, '')
}
} 
dialNr=dialNr.replace(/[^\d\*\#]+/g, '') 
if (dialNr == "") {
return
}
}
if (dialNr == "") dialNr=tableDataSorted[pos+colNrRufnummer]
if (imageID == "") imageID="I"+pos
var dialPortNr = Number(dialPort)
var portName
if (dialPortNr < 50) {
portName=portNames[dialPort-1]
} else {
var pos = dialPort-50
if (pos == 0) {
portName=portNames[4]
} else {
portName=portMSNNames[pos-1] +" (MSN: "+portMSNNr[pos-1]+")"
}
}
if (!confirm("Wollen Sie die Verbindung jetzt herstellen?\n\n Anschluss: "+ portName +"\n Rufnummer: "+ dialNr +"\n")) return;
if (previousDialed != -1){
eval ("document.I"+previousDialed+".src='/htmltsb/i.gif'")
}
if (fromForm != 1) {
previousDialed = pos
} else {
previousDialed = -1
}

var newSource="/cgi-bin/tsb/index.html?dial"+dialPortNr+"_"+dialNr+sid
eval("document."+imageID+".src='"+newSource+"'")
var checkSource=eval("document."+imageID+".src")
checkSource=checkSource.replace(/http:\/\/.*?\//g, '/')
if (checkSource != newSource){
document.Callings.param.value="dial"+dialPortNr+"_"+dialNr+"_page"
document.Callings.action.value="dial"
document.Callings.submit()
}
return
}
function cookieGetKey(key, dft) {
var val = "empty";
if (document.cookie) {
val=eval('document.cookie.replace(/.*[=&]'+key+':([^&;]*).*/, "$1")')
if (val == document.cookie) val = dft
}
if (val == "empty") val = dft
return val
}
function cookieWrite () {
var now = new Date();
var expire = new Date(now.getTime() + cookieLifeTime);
var data=""
for (var i=0; i<cookieKeys.length; i++) {
data+=cookieKeys[i]+":"+eval(cookieKeys[i])+"&"
}
data = data.replace(/&+$/, '')
document.cookie = cookieName + "=" + data + "; path=/; expires=" + expire.toGMTString() +";"
}
function dateStr(d,shortFormat) {
var year = d.getFullYear()
var mon = d.getMonth() 
mon += 1
var day = d.getDate()
var wday = d.getDay()
var hour = d.getHours()
var min = d.getMinutes()
var sec = d.getSeconds()
if (shortFormat == 1) {
shortYear=year-2000
return ((day < 10) ? "0" + day : day) +"."
+((mon < 10) ? "0" + mon : mon) +"."
+((shortYear < 10) ? "0" + shortYear : shortYear) +" "
+((hour < 10) ? "0" + hour : hour) +":"
+((min < 10) ? "0" + min : min)
} else {
return wdayNames[wday] +", "
+((day < 10) ? "0" + day : day) +"."
+((mon < 10) ? "0" + mon : mon) +"."
+ year +" "
+((hour < 10) ? "0" + hour : hour) +":"
+((min < 10) ? "0" + min : min) +":"
+((sec < 10) ? "0" + sec : sec)
}
}
