function suchbox() {
this.form = false;
this.formname = false;
this.content = false;
this.content_id = false;
this.fields = new Array();
this.sfields = new Array();
this.start_sb = true;
this.sf = false;

this.init_suchbox 	= _init_suchbox;
this.reset_fields 	= _reset_fields;
this.add_field 		= _add_field;
this.set_field 		= _set_field;
this.show			= _show;
this.getdata		= _getdata;
this.ref			= _ref;
this.opencontent	= _opencontent;
this.show_sfield	= _show_sfield;
}

function _init_suchbox(id,cont_id) {
var e1 = document.getElementById(id);
if (e1!=null) {
this.form = e1;
this.formname = id;
}
for(i=0;i<document.forms["wk_suche"].elements.length;i++) {
document.forms["wk_suche"].elements[i].onchange = new Function('webkfz.ref();');
}
var e2 = document.getElementById(cont_id);
if (e2!=null) {
this.content = e2;
this.content_id = cont_id;
}
webkfz.getdata();
}

function _reset_fields() {
this.fields.length = 0;
this.sfields.length = 0;
for(i=0;i<document.forms["wk_suche"].elements.length;i++) {
	if (document.forms["wk_suche"].elements[i].name!='wk_ftyp')
		document.forms["wk_suche"].elements[i].options.length=0;
}
}

function _add_field(id,val) {
this.fields[this.fields.length] = {'id' : id, 'val' : val };
}

function _set_field(id,val) {
this.sfields[this.sfields.length] = {'id' : id, 'val' : val };
}

function _show_sfield() {
for (vi=0;vi<this.sfields.length;vi++) {
f1 = this.sfields[vi];
changeVals(f1.id,f1.val);
}
}

function _show() {
var f1 = null;
var last = null;
for (i=0;i<this.fields.length;i++) {
f1 = this.fields[i];
if (f1.id == 'wk_treffer') {
var e2 = document.getElementById(f1.id);
if (e2!=null)
e2.innerHTML = f1.val;
} else {
if (last!=f1.id) {
var e1 = document.getElementById(f1.id);
if (e1!=null && e1.options.length==0)
e1.options[e1.options.length] = new Option('Bitte wählen', '', false, false);
last = f1.id;
}
if (e1!=null)
e1.options[e1.options.length] = new Option(f1.val, f1.val, false, false);
}
}
this.show_sfield();
}

function _getdata() {
var params = Object();
for(i=0;i<document.forms["wk_suche"].elements.length;i++) {
params[document.forms["wk_suche"].elements[i].name] =
	document.forms["wk_suche"].elements[i].value;
}
this.formdata = params;
params['wk_mode'] = 'list';

if (this.start_sb==true)
params['wk_first'] = '1';
new Ajax.Request('/ajax.php', {
method: 'post',
parameters: params,
onSuccess: function(request) {
try {
webkfz.reset_fields();
//window.alert(request.responseText);
eval(String(request.responseText));
//window.alert(request.responseText);
if (webkfz.start_sb==true) {
start_sb();
webkfz.show();
webkfz.start_sb = false;
} else {
webkfz.show();
if (webkfz.content!=null && webkfz.content!=false)
webkfz.opencontent();
}
} catch (e) {

}
}
});
}

function _opencontent() {
var params = Form.serialize(this.formname,true);
this.formdata = params;
params['wk_mode'] = 'listdata';
new Ajax.Request('/ajax.php', {
method: 'post',
parameters: params,
onSuccess: function(request) {
try {
webkfz.content.innerHTML = String(request.responseText);
} catch (e) {

}
}
});
}

function _ref() {
this.getdata();
}


/**
    Bildwechsler
**/ 

var WKBW;

if (!WKBW) {
    WKBW=(function() {
        var fvorschau = '';
        var fvsize = ['',320,240];
        var ftemp = [];
        var bwm = [];
        var check = null;
        function s1() {
            fvorschau = $('wk_bildvorschau');
            if (fvorschau) {
                fvsize = [fvorschau.src,fvorschau.width,fvorschau.height];
            }
            $$('.bwmove').each(function(e1) {
                var Ausdruck = /http:\/\/sab24\.de\/asc\/K\/(\w.+)\/images\/small\/(\w.+)\.jpg/;
                Ausdruck.exec(e1.src);
                var i1 = new Image();
                i1.src = 'http://sab24.de/asc/K/' + RegExp.$1 + '/images/medium/' + RegExp.$2 + '.jpg';
                e1.observe('mouseout',WKBW.setvfirst.bindAsEventListener(this));
                e1.observe('mouseover',WKBW.setvorschau.bindAsEventListener(this,e1,i1));
                this[this.length] = [e1,i1];
                // http://sab24.de/asc/K/k00100/images/medium/8960_1.jpg
                // http://sab24.de/asc/K/k00100/images/medium/8960_1.jpg
            },bwm);
			$$('.winlink').each(function(e1) {
				e1.observe('click',WKBW.openWin.bindAsEventListener(this,e1.href));
				e1.href = '#';
			});
        }
       
        function s2(bild) {
            window.clearTimeout(check);
            if (fvorschau) {
                var faktor = 1;
                if (bild.height>fvorschau.height)
                    faktor = fvorschau.height/bild.height;
                fvorschau.src       = bild.src;
                fvorschau.width     = bild.width*faktor;
                fvorschau.height    = bild.height*faktor;
            }
        }
        
        function s3(x1) {
            if (!x1) {
                check = window.setTimeout(function() {
                    WKBW.setvfirst(null,true);
                }, 300);
                return;
            } else {
                window.clearTimeout(check);
            }
            if (fvorschau) {
                fvorschau.src = fvsize[0];
                fvorschau.width = fvsize[1];
                fvorschau.height = fvsize[2];
            }
        }
		
		function openwin(adresse) {
			  MeinFenster = window.open(adresse, "Fenster", "scrollbars=yes,width=825,height=720");
			  MeinFenster.focus();
		}

		return { 
			start: function() {
				s1();
			},
            setvorschau: function() {
                s2(arguments[2]);
            },
            setvfirst: function() {
                s3(arguments[1] || false);
            },
			openWin: function() {
				openwin(arguments[1] || false);
			}
		}
	}());
}

document.observe('dom:loaded',function() { WKBW.start()});
