//<![CDATA[
var ajax = [];function pjx(args,fname,method) { this.target=args[1]; this.args=args[0]; method=(method)?method:'GET'; if(method=='post'){method='POST';} this.method = method; this.r=ghr(); this.url = this.getURL(fname);}function formDump(){ var all = []; var fL = document.forms.length; for(var f = 0;f<fL;f++){ var els = document.forms[f].elements; for(var e in els){ var tmp = els[e].id || els[e].name; if(typeof tmp != 'string'){continue;} if(tmp){ all[all.length]=tmp} } } return all;}function getVal(id) { if (id.constructor == Function ) { return id(); } if (typeof(id)!= 'string') { return id; } var element = document.getElementById(id) || document.forms[0].elements[id]; if(!element){ alert('ERROR: Cant find HTML element with id or name: ' + id+'. Check that an element with name or id='+id+' exists'); return 0; } if (element.type == 'select-multiple' || (element[0] && element[0].type =='checkbox')) { var ans = []; var k =0; for (var i=0;i<element.length;i++) { if (element[i].selected || element[i].checked ) { ans[k++]=element[i].value; } } return ans; } if(element.type == 'radio'){ var ans =[]; var elms = document.getElementsByTagName('input'); var endk = elms.length; var i =0; for(var k=0;k<endk;k++){ if(elms[k].type=='radio' && elms[k].checked && elms[k].id==id){ ans[i++]=elms[k].value; } } return ans; } if(element.type=='div' || (element.tagName && element.tagName.toUpperCase()=='SPAN')){ return element.innerHTML; }else{ return element.value; }}function fnsplit(arg) { var url=""; if(arg=='NO_CACHE'){return '&pjxrand='+Math.random()} if (arg.indexOf('__') != -1) { arga = arg.split(/__/); url += '&' + arga[0] +'='+ encodeURIComponent(arga[1]); } else { var res = getVal(arg) || ''; if(res.constructor != Array){ res = [res] } for(var i=0;i<res.length;i++) { url += '&args=' + encodeURIComponent(res[i]) + '&' + arg + '=' + encodeURIComponent(res[i]); } } return url;}
	pjx.prototype = { 
	send2perl : function(){ 
	var r = this.r; 
	var dt = this.target; this.pjxInitialized(dt); 
	var url=this.url; var postdata; 
	if(this.method=="POST"){ 
		var idx=url.indexOf('?'); 
		postdata = url.substr(idx+1); 
		url = url.substr(0,idx);
	}
	//alert(url);
		r.open(this.method,url,true); 
	if(this.method=="POST"){ 
		r.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		r.send(postdata); 
	}
	if(this.method=="GET"){ r.send(null);}
	
	r.onreadystatechange = handleReturn; }, pjxInitialized : function(){}, pjxCompleted : function(){}, readyState4 : function(){ var rsp = decodeURIComponent(this.r.responseText); /* the response from perl */ var splitval = '__pjx__'; /* to split text */ /* fix IE problems with undef values in an Array getting squashed*/ rsp = rsp.replace(splitval+splitval+'g',splitval+" "+splitval); var data = rsp.split(splitval); dt = this.target; if (dt.constructor != Array) { dt=[dt]; } if (data.constructor != Array) { data=[data]; } if (typeof(dt[0])!='function') { for ( var i=0; i<dt.length; i++ ) { var div = document.getElementById(dt[i]); if (div.type =='text' || div.type=='textarea' || div.type=='hidden' ) { div.value=data[i]; } else{ div.innerHTML = data[i]; } } } else if (typeof(dt[0])=='function') { var d=data; var str = "dt[0]("; for(m=0;m<d.length-1;m++){ str+= "d[" + m + "],"; } str+="d[" + m +"])"; eval(str); } this.pjxCompleted(dt); }, getURL : function(fname) { var args = this.args; var url= 'fname=' + fname; for (var i=0;i<args.length;i++) { url=url + args[i]; } return url; }};handleReturn = function() { for( var k=0; k<ajax.length; k++ ) { if (ajax[k].r==null) { ajax.splice(k--,1); continue; } if ( ajax[k].r.readyState== 4) { ajax[k].readyState4(); ajax.splice(k--,1); continue; } }};var ghr=getghr();function getghr(){ if(typeof XMLHttpRequest != "undefined") { return function(){return new XMLHttpRequest();} } var msv= ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]; for(var j=0;j<=msv.length;j++){ try { A = new ActiveXObject(msv[j]); if(A){ return function(){return new ActiveXObject(msv[j]);} } } catch(e) { } } return false;}
	function jsdebug(){ var tmp = document.getElementById('pjxdebugrequest').innerHTML = "<br><pre>";
for( var i=0; i < ajax.length; i++ ) { tmp += '<a href= '+ ajax[i].url +' target=_blank>' + decodeURI(ajax[i].url) + ' </a><br>'; } document.getElementById('pjxdebugrequest').innerHTML = tmp + "</pre>";}function JSFUNC() { var args = JSFUNC.arguments; for( var i=0; i<args[0].length;i++ ) { args[0][i] = fnsplit(args[0][i]); } var l = ajax.length; ajax[l]= new pjx(args,"JSFUNC",args[2]); 
	ajax[l].url = '/website/shop/flash/flashhaeder.cgi?' + ajax[l].url; 
	ajax[l].send2perl();
	}
//]]>



addEvent = function(o, e, f, s){
	var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
	r[r.length] = [f, s || o], o[e] = function(e){
		try{
			(e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
			e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
			e.target || (e.target = e.srcElement || null);
			e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
		}catch(f){}
		for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
		return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s){
	for(var i = (e = o["_on" + e] || []).length; i;)
		if(e[--i] && e[i][0] == f && (s || o) == e[i][1])
			return delete e[i];
	return false;
};


AutoComplete = function(form){
	var o = this;
	o.form = document.forms[form], o.fields = {};
	o.d = function(f, v){
		f.box.style.display = v ? "block" : "none";
		v ? o.onShow && o.onShow(f) : o.onHide && o.onHide(f);
	}
	o.rem = function(s){
		var a = {a: "àáãäâå", e: "èéëê", i: "ìíïî", o: "òóõöô", u: "ùúûü", c: "ç", n: "ñ"};
		for(var i in a) s = s.replace(new RegExp("[" + a[i] + "]", "gi"), i);
		return s;
	}
}
AutoComplete.prototype.size = 5;
AutoComplete.prototype.matchExact = true;
AutoComplete.prototype.ignoreAccents = true;
AutoComplete.prototype.addControls = function(field){
	var o = this.form[field], b = o.box, h = this;
	addEvent(o, "keydown", function(e){
		e.key == 40 && b.style.display == "block" && b.focus();
	});
	addEvent(o, "keypress", function(e){
		e.key == 13 && b.style.display == "block" && h.d(o, (b.ondblclick(), e.preventDefault()));
	});
	addEvent(o, "keyup", function(e){
		if(!o.value) return;
		var a, s = b.style, v, l = (v = (h.ignoreAccents ? h.rem(o.value) : o.value).toLowerCase()).length, t = o.list, p = 0;
		if(e.key == 13 && s.display == "block") return b.ondblclick();
		for(var i = t.length; i--;)
			(a = (h.ignoreAccents ? h.rem(t[i]) : t[i]).toLowerCase().indexOf(v), h.matchExact ? !a : a > -1) &&
			t[i].length != l && (b.options[p++] = new Option(t[i], t[i]));
		p && h.d((b.size = ((b.options.length = p) < h.size) ? p : h.size, o), (b.selectedIndex = 0) + 1);
		!p && (b.fo && !b.blur() || (h.d(o, o.focus())));
	});
	addEvent(o, "blur", function(){
		setTimeout(function(){
			return !b.fo && h.d(o, 0);
		}, 15010);
	});
	
	
	
	
	b.onblur = function(){h.d(o, b.f = b.fo = false);}
	b.onfocus = function(){b.fo = true;}
	b.ondblclick = function(){
		h.onSelect && h.onSelect.call(this, b.selectedIndex);
		o.value = b.options[b.selectedIndex].value;
		
		//im ie wird die auswahl vorzeitig versteckt 
		b.fo && b.blur(), o.focus();
		
		
		//debug
		//alert(this);
	}
	addEvent(b, "keypress", function(e){e.key == 8 && o.focus()});
	addEvent(b, "keyup", function(e){
		if(e.key == 13) b.ondblclick();
		else if(e.key == 38)
			!b.selectedIndex && b.f && (b.blur(), o.focus()), b.f = true;
		else b.f = false;
	});
	
	
}
AutoComplete.prototype.addField = function(field, list, cssClass){
	if(this.fields[field]) return;
	var f, v, a, x = ((f = this.form[(this.fields[field] = 1, field)]).list = list, v = f).offsetLeft, y = f.offsetTop, st;
	while(v = v.offsetParent) (y += v.offsetTop, x += v.offsetLeft);
	f.box = document.createElement("select"),  cssClass && (f.box.className = cssClass);
	for(var s in st = f.box.style, a = {display: "none", position: "absolute", width: f.offsetWidth + "px",
		top: (y + f.offsetHeight + 2) + "px", left: x + "px"}) st[s] = a[s];
	return this.addControls((document.body.appendChild(f.box), field));
}
//]]>
