<!--
function seladd(session, type) {
	var w = 320;
	var h = 380;
	var wa = (screen.width-w)/2;
	var ha = (screen.height-h)/2 - 60;
	var features = 'scrollbars=auto,toolbar=no,statusbar=no,menubar=no,resizable=no,width='+w+',height='+h+',top='+ha+',left='+wa;
	var url = 'add_pop.php?session='+session+'&do=add'+type+'pop';
	var addpop = window.open(url, 'Adressbuch', features);
	addpop.focus();
};
function popWin(win, name, w, h) {
	var wa = (screen.width-w)/2;
	var ha = (screen.height-h)/2 - 60;
	var features= 'scrollbars=auto,toolbar=no,statusbar=no,menubar=no,resizable=no,width='+w+',height='+h+',top='+ha+',left='+wa;
	var popwin = window.open(win, name, features);
	popwin.focus();
};
function number_format(number, laenge, sep, th_sep ) {
  number = Math.round( number * Math.pow(10, laenge) ) / Math.pow(10, laenge);
  str_number = number+"";
  arr_int = str_number.split(".");
  if(!arr_int[0]) arr_int[0] = "0";
  if(!arr_int[1]) arr_int[1] = "";
  if(arr_int[1].length < laenge){
    nachkomma = arr_int[1];
    for(i=arr_int[1].length+1; i <= laenge; i++){  nachkomma += "0";  }
    arr_int[1] = nachkomma;
  }
  if(th_sep != "" && arr_int[0].length > 3){
    Begriff = arr_int[0];
    arr_int[0] = "";
    for(j = 3; j < Begriff.length ; j+=3){
      Extrakt = Begriff.slice(Begriff.length - j, Begriff.length - j + 3);
      arr_int[0] = th_sep + Extrakt +  arr_int[0] + "";
    }
    str_first = Begriff.substr(0, (Begriff.length % 3 == 0)?3:(Begriff.length % 3));
    arr_int[0] = str_first + arr_int[0];
  }
  return arr_int[0]+sep+arr_int[1];
}
function chsigns(elem, allowed) {
	/*
	allowed z.B.: "abcdefghijklmnopqrstuvwxyz -" für Vor- bzw. Nachname
	*/
	n=0;
	newtext='';
	while(n != elem.value.length){
		word_char = elem.value.charAt(n);
		check = word_char.toLowerCase();
		if(allowed.indexOf(check) != -1){
			newtext = newtext + word_char;
		}
	n++;
	};
	elem.value = newtext;	
};

var xmlHttp = null;
var wert_global = '';
var original_value = '';
var text = '';
var highlight_id = '';
var results = 0;
var results_array = new Array();

function daten() {
	var ausgabe = '';
	results = 0;
	if (xmlHttp.readyState == 4) {
		text = unescape(xmlHttp.responseText);
		
		if (text != "") {
			textteile = text.split(";");
			for ($i = 0; $i <= textteile.length-1; $i++){
				textteile_2 = textteile[$i].split(",");
				number = String(textteile_2[0]);
				ausgabe += "<div onclick='document.getElementById(\"add_numbers\").style.visibility = \"hidden\";' onmouseover='highlight_this(this)' onmouseout='unhighlight_this(this)' id='highlight_" + $i + "'>" + number + " (" + textteile_2[2] + ", " + textteile_2[1] + ")</div>";
				results_array[$i] = number;
			}
			results = $i;
			document.getElementById('add_numbers').innerHTML = ausgabe;
		}
		if (ausgabe != "") {
			document.getElementById('add_numbers').style.visibility = "visible";
		} else {
			document.getElementById('add_numbers').style.visibility = "hidden";
		}
	}
}
function highlight_this(obj) {
	obj.style.backgroundColor = '#EEEEEE';
	highlight_id = obj.id.replace("highlight_", "");
	for ($i = 0; $i <= results-1; $i++){
		if($i != highlight_id){
			document.getElementById(('highlight_'+($i))).style.backgroundColor = '#FFFFFF';
		}
	}
	document.getElementById('to').value = results_array[highlight_id];
}
function unhighlight_this(obj) {
	obj.style.backgroundColor = '#FFFFFF';
	if(document.getElementById('add_numbers').style.visibility == "visible") document.getElementById('to').value = original_value;
	highlight_id = '';
}
function key_functions(what) {
	var obj = new Object();
	if(what == 'up' && document.getElementById('add_numbers').style.visibility != "visible") return;
	if(highlight_id == '' && what != 'up'){
		obj = document.getElementById('highlight_0');
	}
	else{
		highlight_id = Number(highlight_id);
		if(what == 'down') obj_id = 'highlight_'+(highlight_id+1);
		if(what == 'up') obj_id = 'highlight_'+(highlight_id-1);
		obj = document.getElementById(obj_id);
		if(!obj){
			obj = document.getElementById('highlight_0');
			if(what == 'up'){
				unhighlight_this(obj);
				document.getElementById('add_numbers').style.visibility = 'hidden';
				return;
			}
		}
	}
	highlight_this(obj);
	if(document.getElementById('add_numbers').style.visibility != "visible") document.getElementById('add_numbers').style.visibility = "visible";
}
function handle_key(e)
{
	//chsigns(document.getElementById('to'), '0123456789');
	if (!e) e = window.event;
	key = (e.which) ? e.which : e.keyCode;
	//alert(key);
	switch (key) {
		case 13: // enter
		highlight_id = '';
		document.getElementById('add_numbers').style.visibility = 'hidden';
		return false;
		break;
		case 38: // up arrow
		key_functions('up');
		return false;
		break;
		case 40: // down arrow
		if(document.getElementById('add_numbers').style.visibility == 'hidden'){
			suggest_address(document.getElementById('to').value);
			return;
		}
		key_functions('down');
		return false;
		break;
		default:
		suggest_address(document.getElementById('to').value);
	}
	return true;
}
//-->