napexpath = '';

function popupwindow(url,name,w,h) {
	if(name == "help")
		var attributes = "width=" + w + ",height=" + h + ",status=yes,dependent=yes,resizable=yes,scrollbars=yes,toolbar=yes";
	else
		var attributes = "width=" + w + ",height=" + h + ",status=yes,dependent=yes,resizable=yes,scrollbars=yes";
	var popup = window.open(url,name,attributes);
	popup.focus();
}

function popup(url,w,h) {
	var attributes = "scroll:yes;help:no;dialogWidth:" + w + "px;dialogHeight:" + h + "px";
	var rValue = window.showModalDialog(url,true,attributes);
	if(rValue && (rValue!=""))
	location.href = rValue;
}

function imageview(image,copyright,windowtitle) {
	var attributes = "width=" + 300 + ",height=" + 200 + ",status=yes,dependent=yes,resizable=yes,scrollbars=yes";
	if(!copyright)
		var copyright = "";
	if(!windowtitle)
		var windowtitle = "";
	image = image.replace(/&/g,"§amp;");
	var url = "/" + napexpath + "napex/apps/imageview/index.cfm?image=" + image + "&copyright=" + copyright + "&windowtitle=" + windowtitle;
	var popup = window.open(url,'imageview',attributes);
	popup.focus();
}

function alwaysinfront() {
	self.focus();
	window.setTimeout("alwaysinfront()",100);
}

function infoBox(id,width,height) {
  block = document.getElementById(id);
  if(width)
    block.style.width = width + "px";
  else
    width = 0;
  if(height)
    block.style.height = height + "px";
  else
    height = 0;
  if(navigator.appName == "Microsoft Internet Explorer") {
    block.style.left = getPosition().x + "px";
    block.style.top = getPosition().y + 10 + "px";
  }
  else
    AssignPosition(block);
  
  //block.style.left = mouse.x + "px";
  //block.style.top = mouse.y + 10 + "px";
  //block.style.left = getWindowWidth()/2 - width/2 + "px";
  //block.style.top = getWindowHeight()/2 - height/2 + "px";
  block.style.padding = "5px 5px 5px 5px";
  block.style.border = "1px solid #777777";
  block.style.backgroundColor = "white";
  //var closeButton = "<a href='#' onclick='infoBoxClose(\"" + id + "\");'>Schließen</a><br /><br />";
  var closeButton = "<a href='#' onclick='infoBoxClose(\"" + id + "\");'><img src='http://napex.net/napex/images/system/close_on.gif' width=16 height=16 align=absmiddle vspace=2 hspace=2 border=0>Schließen</a><br />";
  if(block.innerHTML.indexOf("infoBoxClose") <= 0)
    block.innerHTML =   closeButton + block.innerHTML;
  block.style.display = "block";
}
function infoBoxClose(id) {
  document.getElementById(id).style.display = "none";
}
function getWindowWidth(win)
{
    if (win == undefined)
        win = window;
    if (win.innerWidth) {
        return win.innerWidth;
    } else {
        if (win.document.documentElement 
                && win.document.documentElement.clientWidth) 
        {
            return win.document.documentElement.clientWidth;
        }
        return win.document.body.offsetWidth;
    }
}
function getWindowHeight(win)
{
    if (win == undefined)
        win = window;
    if (win.innerHeight) {
        return win.innerHeight;
    } else {
        if (win.document.documentElement 
                && win.document.documentElement.clientHeight) 
        {
            return win.document.documentElement.clientHeight;
        }
        return win.document.body.offsetHeight;
    }
}

var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
d.style.left = (cX+10) + "px";
d.style.top = (cY+10) + "px";
}

function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}

/*function Replace(string,substring1,substring2,scope) {
	var result = string
	substring1 = escape(substring1);
	if(scope.toLowerCase == "all") {
		substring1 = "/" + substring1 + "/g";
		string = string.replace(substring1,substring2)
	}
	else {
		substring1 = "/" + substring1 + "/";
		string = string.replace(substring1,substring2) 
	}
	return string;
}

function ReplaceNoCase(string,substring1,substring2,scope) {
	var result = string
	substring1 = escape(substring1);
	if(scope.toLowerCase == "all") {
		substring1 = "/" + substring1 + "/ig";
		string = string.replace(substring1,substring2)
	}
	else {
		substring1 = "/" + substring1 + "/i";
		string = string.replace(substring1,substring2) 
	}
	return string;
}*/

// numeric functions

function iint(number) {
	number = parseInt(number);
	if(isNaN(number))
		number = 0;
	return number;
}

function ListFind(list,value,delimiters) {
	var result = 0;
	var del;
	delimiters ? del = delimiters : del = ",";
	listarray = list.split(del);
	for (var i=0;i<listarray.length;i++) {
		if(listarray[i] == value)
			result = i+1;
	}
	return result;
}

function ListFirst(list,delimiters) {
	var result = 0;
	var del;
	delimiters ? del = delimiters : del = ",";
	listarray = list.split(del);
	result = listarray[0];
	return result;
}

function ListLast(list,delimiters) {
	var result = 0;
	var del;
	delimiters ? del = delimiters : del = ",";
	listarray = list.split(del);
	result = listarray[listarray.length-1];
	return result;
}

function ListRest(list,delimiters) {
	var result = "";
	var del;
	delimiters ? del = delimiters : del = ",";
	listarray = list.split(del);
	for (var i=1;i<listarray.length;i++) {
		result += listarray[i] + (i<listarray.length-1 ? del : "");
	}
	return result;
}

function ListAppend(list,value,delimiters) {
	var result = "";
	var del;
	delimiters ? del = delimiters : del = ",";
	if(list == "")
		result = value;
	else
		result = list + del + value;
	return result;
}

function ListGetAt(list,position,delimiters) {
	var result = "";
	var del;
	delimiters ? del = delimiters : del = ",";
	listarray = list.split(del);
	for (var i=0;i<=listarray.length;i++) {
		if(i == position)
			result = listarray[i-1];
	}
	return result;
}

function ListDeleteAt(list,position,delimiters) {
	var result = "";
	var del;
	delimiters ? del = delimiters : del = ",";
	listarray = list.split(del);
	for (var i=0;i<listarray.length;i++) {
		if(i+1 != position)
			result += listarray[i] + (i<listarray.length-1 ? del : "");
	}
	if(result.charAt(result.length-1) == del)
		result = result.substring(0,result.length-1);
	return result;
}

function ListLen(list,delimiters) {
	var result = "";
	var del;
	delimiters ? del = delimiters : del = ",";
	listarray = list.split(del);
	result = listarray.length;
	if(list == "")
		result = 0;
	return result;
}

function setODBCDate(date) {
        if(date.getDate()) {
                var day = date.getDate();
                var month = date.getMonth()+1;
                var year = date.getFullYear();
        }
        else {
                datestring = date.split(".");
                year = datestring[2];
                month = datestring[1];
                day = datestring[0];
        }
        if(String(month).length < 2)
                month = "0" + String(month);
        if(String(day).length < 2)
                day = "0" + String(day);
        odbcdate = "{d '"+year+"-"+month+"-"+day+"'}";
        return odbcdate;
}

function odbcDateConvert(ODBCDate) {
	var result = "";
	if(ODBCDate != "") {
		var convertedDate = ODBCDate.split("-");
		var convertedTime = convertedDate[2].split(" ")[1].split(":");
		convertedDate = new Date(convertedDate[0],convertedDate[1]-1,convertedDate[2].split(" ")[0],convertedTime[0],convertedTime[1],convertedTime[2]);
		result = convertedDate.toLocaleString();
	}
	return result;
}

function parseDate(datestring) {
	var result = "";
	if(datestring != "") {
		var convertedDate = datestring.split(".");
		convertedDate = new Date(convertedDate[2],convertedDate[1]-1,convertedDate[0]);
		result = convertedDate;
	}
	return result;
}

function DateAdd( datepart, number, date ) {

    // Create 3 error messages, 1 for each argument. 
    var dateMsg = "Sorry the date parameter of the dateAdd function\n"
        dateMsg += "must be a valid date format.\n\n"
        dateMsg += "Please try again." ;
		
    var datepartMsg = "Sorry the dateAdd function only accepts\n"
        datepartMsg += "d, h, m OR s dateparts.\n\n"
        datepartMsg += "Please try again." ;

    var numberMsg = "Sorry the number parameter of the dateAdd function\n"
        numberMsg += "must be numeric.\n\n"
        numberMsg += "Please try again." ;
		
    // get the milliseconds for this Date object. 
    var buffer = Date.parse( date ) ;
	
    // check that the date parameter is a valid Date. 
    if ( isNaN (buffer) ) {
        alert( dateMsg ) ;
        return null ;
    }
	
    // check that an datepart parameter was not numeric. 
    if ( datepart.charAt == 'undefined' ) {
        // the user specified an incorrect datepart, handle the error. 
        alert( datepartMsg ) ;
        return null ;
    }

    // check that the number parameter is numeric. 
    if ( isNaN ( number ) )	{
        alert( numberMsg ) ;
        return null ;
    }

    // so far, so good...
    //
    // what kind of add to do? 
    switch (datepart.charAt(0))
    {
        case 'd': case 'D': 
            number *= 24 ; // days to hours
            // fall through! 
        case 'h': case 'H':
            number *= 60 ; // hours to minutes
            // fall through! 
        case 'm': case 'M':
            number *= 60 ; // minutes to seconds
            // fall through! 
        case 's': case 'S':
            number *= 1000 ; // seconds to milliseconds
            break ;
        default:
        // If we get to here then the datepart parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error. 		
        alert(datepartMsg) ;
        return null ;
    }
    return new Date( buffer + number ) ;
}

function DateFormat(date, mask) {
	var thisday = date.getDate();
	var thismonth = date.getMonth()+1;
	switch (mask) {
	case "d.m.yy" :
		var thisyear = date.getYear();
	break;
	case "dd.mm.yy" :
		if(thisday < 10)
			thisday = "0" + thisday;
		if(thismonth < 10)
			thismonth = "0" + thismonth;
		var thisyear = date.getYear();
	break;
	case "dd.mm.yyyy" :
		if(thisday < 10)
			thisday = "0" + thisday;
		if(thismonth < 10)
			thismonth = "0" + thismonth;
		var thisyear = date.getFullYear();
	break;
	default :
		var thisyear = date.getYear();
	break;
	}
	return thisday + "." + thismonth + "." + thisyear;
}

function Replace(string,searchString,replaceString)
     {
     var searchString = searchString.split('~');
     var replaceString = replaceString.split('~');
     var searchvalues = 0;
     var flow = 0;

 var serStrings = searchString.length;
     var repStrings = replaceString.length;

 if (serStrings != repStrings) {
      alert('Fehlende Argumente');
          return
     }
 else if (serStrings == repStrings) {
  for (i = 0; i < serStrings; i ++) {
    if (searchString[i] == replaceString[i]) {
    alert('searchString: '+searchString[i]+', entspicht replaceString: '+replaceString[i] + '- Funktion abgebrochen.')
    return
   }
  }
 }
while (flow < serStrings)
 {
 while (searchvalues != -1)
  {
  string = string.replace(searchString[flow],replaceString[flow]);
   searchvalues = string.indexOf(searchString[flow])
  }
 flow ++;
 searchvalues = 0;
 }
return string
}

function htmlToText(htmlMarkup) {
        var div = document.createElement('div');
        div.innerHTML = htmlMarkup;
        if (typeof div.innerText != 'undefined') {
                return div.innerText;
        }
        else if (typeof div.ownerDocument != 'undefined' && typeof div.ownerDocument.createRange != 'undefined') {
                var range = div.ownerDocument.createRange();
                range.selectNodeContents(div);
                return range.toString();
        }
        else if (typeof div.textContent != 'undefined') {
                return div.textContent;
        }
}

function tFix(wert,ds) {
	var wert=(wert.toFixed)?wert.toFixed(ds):Math.floor(wert)+"."+(Math.pow(10,ds)+Math.round((wert-Math.floor(wert))* Math.pow(10,ds))+"").substr(1,ds);
	return wert;
}

function tFixComma(wert,ds) {
	var wert=(wert.toFixed)?wert.toFixed(ds):Math.floor(wert)+"."+(Math.pow(10,ds)+Math.round((wert-Math.floor(wert))* Math.pow(10,ds))+"").substr(1,ds);
	wert = wert.replace(/\./,",");
	return wert;
}

//-----------------------------------------------------------------------------
// sortTable(id, col, rev)
//
//  id  - ID of the TABLE, TBODY, THEAD or TFOOT element to be sorted.
//  col - Index of the column to sort, 0 = first column, 1 = second column,
//        etc.
//  rev - If true, the column is sorted in reverse (descending) order
//        initially.
//
// Note: the team name column (index 1) is used as a secondary sort column and
// always sorted in ascending order.
//-----------------------------------------------------------------------------

function sortTable(id, col, rev) {

  // Get the table or table section to sort.
  var tblEl = document.getElementById(id);

  // The first time this function is called for a given table, set up an
  // array of reverse sort flags.
  if (tblEl.reverseSort == null) {
    tblEl.reverseSort = new Array();
    // Also, assume the team name column is initially sorted.
    tblEl.lastColumn = 1;
  }

  // If this column has not been sorted before, set the initial sort direction.
  if (tblEl.reverseSort[col] == null)
    tblEl.reverseSort[col] = rev;

  // If this column was the last one sorted, reverse its sort direction.
  if (col == tblEl.lastColumn)
    tblEl.reverseSort[col] = !tblEl.reverseSort[col];

  // Remember this column as the last one sorted.
  tblEl.lastColumn = col;

  // Set the table display style to "none" - necessary for Netscape 6 
  // browsers.
  var oldDsply = tblEl.style.display;
  tblEl.style.display = "none";

  // Sort the rows based on the content of the specified column using a
  // selection sort.

  var tmpEl;
  var i, j;
  var minVal, minIdx;
  var testVal;
  var cmp;

  for (i = 0; i < tblEl.rows.length - 1; i++) {

    // Assume the current row has the minimum value.
    minIdx = i;
    minVal = getTextValue(tblEl.rows[i].cells[col]);

    // Search the rows that follow the current one for a smaller value.
    for (j = i + 1; j < tblEl.rows.length; j++) {
      testVal = getTextValue(tblEl.rows[j].cells[col]);
      cmp = compareValues(minVal, testVal);
      // Negate the comparison result if the reverse sort flag is set.
      if (tblEl.reverseSort[col])
        cmp = -cmp;
      // Sort by the second column (team name) if those values are equal.
      if (cmp == 0 && col != 1)
        cmp = compareValues(getTextValue(tblEl.rows[minIdx].cells[1]),
                            getTextValue(tblEl.rows[j].cells[1]));
      // If this row has a smaller value than the current minimum, remember its
      // position and update the current minimum value.
      if (cmp > 0) {
        minIdx = j;
        minVal = testVal;
      }
    }

    // By now, we have the row with the smallest value. Remove it from the
    // table and insert it before the current row.
    if (minIdx > i) {
      tmpEl = tblEl.removeChild(tblEl.rows[minIdx]);
      tblEl.insertBefore(tmpEl, tblEl.rows[i]);
    }
  }

  // Set team rankings.
  //setRanks(tblEl, col, rev);

  // Restore the table's display style.
  tblEl.style.display = oldDsply;

  return false;
}

//-----------------------------------------------------------------------------
// Functions to get and compare values during a sort.
//-----------------------------------------------------------------------------

// This code is necessary for browsers that don't reflect the DOM constants
// (like IE).
if (document.ELEMENT_NODE == null) {
  document.ELEMENT_NODE = 1;
  document.TEXT_NODE = 3;
}

function getTextValue(el) {

  var i;
  var s;

  // Find and concatenate the values of all text nodes contained within the
  // element.
  s = "";
  for (i = 0; i < el.childNodes.length; i++)
    if (el.childNodes[i].nodeType == document.TEXT_NODE)
      s += el.childNodes[i].nodeValue;
    else if (el.childNodes[i].nodeType == document.ELEMENT_NODE &&
             el.childNodes[i].tagName == "BR")
      s += " ";
    else
      // Use recursion to get text within sub-elements.
      s += getTextValue(el.childNodes[i]);

  return normalizeString(s);
}

function compareValues(v1, v2) {
  var d1, d2, f1, f2;
  v1 = v1.toLowerCase();
  v2 = v2.toLowerCase();
  
  // If the values are dates, convert them to dates.
  d1 = parseDate(v1);
  d2 = parseDate(v2);
  if (!isNaN(d1) && !isNaN(d2)) {
    v1 = d1;
    v2 = d2;
  }
  else {
  // If the values are numeric, convert them to floats.
  f1 = parseFloat(v1);
  f2 = parseFloat(v2);
  if (!isNaN(f1) && !isNaN(f2)) {
    v1 = f1;
    v2 = f2;
  }
  }

  // Compare the two values.
  if (v1 == v2)
    return 0;
  if (v1 > v2)
    return 1
  return -1;
}

// Regular expressions for normalizing white space.
var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
var whtSpMult = new RegExp("\\s\\s+", "g");

function normalizeString(s) {

  s = s.replace(whtSpMult, " ");  // Collapse any multiple whites space.
  s = s.replace(whtSpEnds, "");   // Remove leading or trailing white space.

  return s;
}

//-----------------------------------------------------------------------------
// Functions to update the table appearance after a sort.
//-----------------------------------------------------------------------------

// Style class names.
var rowClsNm = "alternateRow";
var colClsNm = "sortedColumn";

// Regular expressions for setting class names.
var rowTest = new RegExp(rowClsNm, "gi");
var colTest = new RegExp(colClsNm, "gi");

function setRanks(tblEl, col, rev) {

  // Determine whether to start at the top row of the table and go down or
  // at the bottom row and work up. This is based on the current sort
  // direction of the column and its reversed flag.

  var i    = 0;
  var incr = 1;
  if (tblEl.reverseSort[col])
    rev = !rev;
  if (rev) {
    incr = -1;
    i = tblEl.rows.length - 1;
  }

  // Now go through each row in that direction and assign it a rank by
  // counting 1, 2, 3...

  var count   = 1;
  var rank    = count;
  var curVal;
  var lastVal = null;

  // Note that this loop is skipped if the table was sorted on the name
  // column.
  while (col > 1 && i >= 0 && i < tblEl.rows.length) {

    // Get the value of the sort column in this row.
    curVal = getTextValue(tblEl.rows[i].cells[col]);

    // On rows after the first, compare the sort value of this row to the
    // previous one. If they differ, update the rank to match the current row
    // count. (If they are the same, this row will get the same rank as the
    // previous one.)
    if (lastVal != null && compareValues(curVal, lastVal) != 0)
        rank = count;
    // Set the rank for this row.
    tblEl.rows[i].rank = rank;

    // Save the sort value of the current row for the next time around and bump
    // the row counter and index.
    lastVal = curVal;
    count++;
    i += incr;
  }

  // Now go through each row (from top to bottom) and display its rank. Note
  // that when two or more rows are tied, the rank is shown on the first of
  // those rows only.

  var rowEl, cellEl;
  var lastRank = 0;

  // Go through the rows from top to bottom.
  for (i = 0; i < tblEl.rows.length; i++) {
    rowEl = tblEl.rows[i];
    cellEl = rowEl.cells[0];
    // Delete anything currently in the rank column.
    while (cellEl.lastChild != null)
      cellEl.removeChild(cellEl.lastChild);
    // If this row's rank is different from the previous one, Insert a new text
    // node with that rank.
    if (col > 1 && rowEl.rank != lastRank) {
      cellEl.appendChild(document.createTextNode(rowEl.rank));
      lastRank = rowEl.rank;
    }
  }
}

// End sortTable

// base64
/*
	var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 
	
	function base64encode(str) { 
	var out;var i; var len; 
	var c1; var c2; var c3; 
	
	var len = str.length; 
	var i = 0; 
	out = ""; 
	while(i < len) { 
	c1 = str.charCodeAt(i++) & 0xff; 
	if(i == len) 
	{ 
	out += base64EncodeChars.charAt(c1 >> 2); 
	out += base64EncodeChars.charAt((c1 & 0x3) << 4); 
	out += "=="; 
	break; 
	} 
	c2 = str.charCodeAt(i++); 
	if(i == len) 
	{ 
	out += base64EncodeChars.charAt(c1 >> 2); 
	out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)); 
	out += base64EncodeChars.charAt((c2 & 0xF) << 2); 
	out += "="; 
	break; 
	} 
	c3 = str.charCodeAt(i++); 
	out += base64EncodeChars.charAt(c1 >> 2); 
	out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)); 
	out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)); 
	out += base64EncodeChars.charAt(c3 & 0x3F); 
	} 
	return out; 
	}
*/
