var ns = document.layers ? true : false;
var ie = document.all && !window.opera ? true : false;;    // IEs
var dom = document.getElementById && !ie ? true : false;  // DOM-Browser
var time = 0;


function changePassword(){
	// passwort über graybox änderbar
	hideSelect();
	
	//$('gray_box').show();
	$('gray_overlay').show();
	
	$('gray_box_content').innerHTML = "<table border='0' width='300' cellspacing='0' cellpadding='5'><tr><td colspan='2' align='left' style='font-size: 16px; font-weight: bold;'>Passwort &auml;ndern</td></tr><tr><td align='right'>Altes Passwort:</td><td align='left'><input type='password' name='old_pw' class='pw_password' id='old_pw'></td></tr><tr><td align='right'>Neues Passwort:</td><td align='left'><input type='password' name='new_pw' class='pw_password' id='new_pw'></td></tr><tr><td align='right'>Passwort wiederholen:</td><td align='left'><input type='password' name='new_pw_wdh' class='pw_password' id='new_pw_wdh'></td></tr><tr><td><div id='pwloading' style='display: none;'><img src='images/loading_small2.gif' /> <img src='images/loading_font.gif' /></div>&nbsp;</td><td align='left'><input type='button' style='background-image:url(images/btn_pwaendern.gif);width:128px;height:18px;border:none;' onClick='passwortUebernehmen();'></td></tr></table>";
	center('gray_box');
}

function passwortUebernehmen(){
	var pwvgl;
	$('pwloading').show();
	new Ajax.Request('ajax/md5.php',
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		parameters: 'str='+$('old_pw').value,
		onComplete: function(t) {	
			pwvgl=t.responseText;
			if($('new_pw')){
				//alert($('md5pw').value + "\n\n" + pwvgl);
				if(pwvgl!=$('md5pw').value){
					alert('Altes Passwort ist nicht korrekt.');
				}
				else if($('new_pw').value!=$('new_pw_wdh').value){
					alert('Neues Passwort stimmt nicht mit der Wiederholung überein.');
				}
				else if($('new_pw').value.length<6){
					alert('Neues Passwort muss mindestens 6 Zeichen haben.');
				}
				else{
					// alles klar - passwort ändern
					new Ajax.Request('ajax/profil.php?changepw=true',
					{
						method: 'post',
						asynchronous: true,
						evalScript: true,
						postBody: 'new_passwort='+$('new_pw').value,
						onComplete: function(t) {	
							showSelect();
							hideAllBoxes();
							$('hbprofil').update(t.responseText);
							$('profilresponse').innerHTML="Ihr Passwort wurde erfolgreich ge&auml;ndert.";
						},
						onFailure: function(t) {
							alert('Passwort konnte nicht geändert werden:\n\n'+t.status+' -- '+t.statusText);	
						}
					}
					);
				}
			}
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Crypt-Error ' + t.status + ' -- ' + t.statusText);
		}		
	},
	$('pwloading').hide()
	);	
}

function profilAendern(){
	$('profil_loading').show();
	new Ajax.Request('ajax/profil.php',
		{
			method: 'post',
			asynchronous: true,
			evalScript: true,
			postBody: $('profilform').serialize(),
			onComplete: function(t) {	
				showSelect();
				hideAllBoxes();
				$('hbprofil').update(t.responseText);
				$('profil_loading').hide();
				$('profilresponse').innerHTML = "Daten wurde erfolgreich ge&auml;ndert.";
			},
			onFailure: function(t) {
				alert('Passwort konnte nicht geändert werden:\n\n'+t.status+' -- '+t.statusText);	
			}
		}
		);	
}

function ausstellersuche(form){
	//alert($('hidden_suche').value + " - " + form);
	$('hidden_suche').value=form;
	//alert($('hidden_suche').value);
	form="suche";
	//alert($(form+'_result').innerHTML);
	$(form+'_result').show();
	$(form+'_result').innerHTML=$(form+'_loading').innerHTML;
	//alert($(form+'_result').innerHTML);
//	$(form+'_loading').show();

	new Ajax.Request('ajax/aussteller.php',
		{
			method: 'post',
			asynchronous: true,
			evalScript: true,
			postBody: $(form+'_form').serialize(),
			onComplete: function(t) {	
				//alert( $(form+'_result').innerHTML);
				//showSelect();
				//hideAllBoxes();
				//alert($(form+'_form').serialize());
				//$(form+'_result').innerText=t.responseText;
				//document.all[form+'_result'].innerHTML="test"; //t.responseText;
				$(form+'_result').update(t.responseText);
				//alert( $(form+'_result').innerHTML);
				//alert(t.responseText);
				//$(form+'_loading').hide();
				
				$(form+'_result').show();
				//if(ie)
				//else
				time = window.setTimeout("ausstellerergebnis('"+$('hidden_suche').value+"','0');",2000);
				
				//$(form+'_status').innerHTML='[+]';
				//$(form).hide();
			},
			onFailure: function(t) {
				alert('Suche konnte nicht durchgef&uuml;hrt werden:\n\n'+t.status+' -- '+t.statusText);	
			}
		}
		);	
}

var http_request = false;

function macheRequest(url) {

        http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // zu dieser Zeile siehe weiter unten
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Ende :( Kann keine XMLHTTP-Instanz erzeugen');
            return false;
        }
        http_request.onreadystatechange = alertInhalt;
        http_request.open('GET', url, true);
        http_request.send(null);

    }
	
function alertInhalt() {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                $('suche_result').update(http_request.responseText);
            } else {
                alert('Bei dem Request ist ein Problem aufgetreten.');
            }
        }

    }
	
	
	
function ausstellerergebnis(form,start,get){
	v=location.search.substring(1, location.search.length).split('&');
	getVars = new Array();
	katDing=68;
	//if(ie) alert(v);
	for(i=0;i<v.length;i++){
		x=v[i];
	//for(var x in v){
		
	 var temp = x.split('=');
	 //alert(temp);
	 if(temp[0]=='kat') katDing=temp[1];
	
	 //getVars[temp[0]] = temp[1];
	}
	//alert(katDing);
	//window.status=katDing;
	
	var sftype=form;
	//alert('ajax/aussteller.php?sftype='+sftype+'&start='+start+'&'+get);
	//alert(form);
	form="suche";
	//$(form+'_result').innerHTML=$(form+'_loading').innerHTML;
	$(form+'_loading').show();
	//alert(limit);
	//
	//
	//
	if(ie) changeKat(katDing,"result=true&typ="+$('hidden_suche').value+"&sftype="+sftype+"&start="+start+"&extended="+$('extended_get').value+"&"+get);
	else macheRequest('ajax/aussteller.php?sftype='+sftype+'&start='+start+'&extended='+$('extended_get').value+'&'+get);
	$(form+'_loading').hide();
/*
	
	new Ajax.Request('ajax/aussteller.php?sftype='+sftype+'&start='+start+'&'+get,
		{
			method: 'get',
			asynchronous: true,
			evalScript: true,
			onComplete: function(t) {	
			//alert($(form+'_result'));
			if(eie){
				//alert($('ie_suche_result').innerHTML);
			 	$('ie_suche_result').update(t.responseText);
				$('suche_result').hide();
				$('ie_suche_result').show();
			}
			else{
				$('suche_result').update(t.responseText);
			}
			 //window.status="Suche abgeschlossen";
			   $('suche_loading').hide();
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}		
		}
		);	*/
}

/////////////////////////
 // Graybox Stuff Start //
/////////////////////////
function showGrayBox() {
	center('gray_box');
	$('gray_overlay').show(); 
	hideSelect();
    return false;
}

function hideGrayBox(){
	$('gray_box').hide();
    $('gray_overlay').hide();
	$('gray_overlay').style.height = "1px";
	showSelect();
	$('gray_box_content').innerHTML = '<img src="images/loading_small2.gif" /><img src="images/loading_font.gif" />';
    return false;
}

function showGrayBox2() {
	center('gray_box2');
	$('gray_overlay2').show(); 
	hideSelect();
    return false;
}

function showGrayBox3() {
	center('gray_box3');
	$('gray_overlay3').show(); 
	//hideSelect();
    return false;
}

function hideGrayBox2(){
	$('gray_box2').hide();
    $('gray_overlay2').hide();
	$('gray_overlay2').style.height = "1px";
	showSelect();
	$('gray_box_content2').innerHTML = '<img src="images/loading_small2.gif" /><img src="images/loading_font.gif" />';
    return false;
}
function hideGrayBox3(){
	$('gray_box3').hide();
    $('gray_overlay3').hide();
	//$('gray_overlay3').style.height = "1px";
	//showSelect();
	$('gray_box_content3').innerHTML = '<img src="images/loading_small2.gif" /><img src="images/loading_font.gif" />';
    return false;
}

function showPinkBox() {
	$('gray_overlay').show(); 
	hideSelect();
    return false;
}

function hidePinkBox(){
    $('pink_box').hide();
	$('gray_overlay').hide();
	showSelect();
    return false;
}

function hideAllBoxes(){
	hideGrayBox();
	//hidePinkBox();	
}

function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	
	//alert(window.document.body.offsetHeight + " - " + document.body.clientHeight + " - " + document.documentElement.clientHeight + " - " + window.innerHeight + " - " + document.documentElement.scrollTop);
    
	element.style.position = 'absolute';
    //element.style.zIndex   = 99;

    var elementDimensions = Element.getDimensions(element);

	//alert(elementDimensions.width + " " + element +" " + elementDimensions.height);
	topsize = arrayPageScroll[1] + ((arrayPageSize[3] - elementDimensions.height) / 2);
	if(topsize < 5) topsize = 5;
	
	element.style.top = (topsize + 'px');
	element.style.left = (((arrayPageSize[0] - elementDimensions.width) / 2) + 'px');

    element.style.display  = 'block';
	
	//Größe verändern	
	if(ie) breite = arrayPageSize[0]+"px";
	else breite = "100%";
	
	if(element.id == "gray_box2") {
		$('gray_overlay2').style.width = breite;
		$('gray_overlay2').style.height = arrayPageSize[1]+"px";
		
	} else {
		$('gray_overlay').style.width = breite;
		$('gray_overlay').style.height = arrayPageSize[1]+"px";
	}
	//alert(arrayPageSize[0] + " - " + arrayPageSize[1] + " - " + arrayPageSize[2] + " - " + arrayPageSize[3]);
	//alert(arrayPageScroll[0] + " - " + arrayPageScroll[1]);
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight =  yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
/*
\\\\\\\\\\\\\\\\\\\\\\\\
 \\ Graybox Stuff ENDE \\
  \\\\\\\\\\\\\\\\\\\\\\\\
*/

function hideSelect() {
	selects = parent.document.getElementsByTagName( 'select' );
   	for ( i = 0; i != selects.length; i++ )
	{
		selects[i].style.visibility = 'hidden';
    }
}

function showSelect() {
	selects = parent.document.getElementsByTagName( 'select' );
    for ( i = 0; i != selects.length; i++ )
	{
		selects[i].style.visibility = 'visible';
	}
}


//OpenLogin
function openLogin() {
	showGrayBox();
	new Ajax.Request('modules_gb/login.php',
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}



function pwVergessen() {
	$('gray_box_content').innerHTML = '<img src="images/loading_small2.gif" alt="" /><img src="images/loading_font.gif" alt="" />';
	new Ajax.Request('modules_gb/lostpw.php',
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

//Logincheck
function checkLogin() {
	$('login_loading').show();
	new Ajax.Request('ajax/login.php',
	{
		method: 'post',
		postBody: $('login_form').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('login_loading').hide();	
		   $('login_result').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function checkLogin2() {
	$('login_loading2').show();
	new Ajax.Request('ajax/login2.php',
	{
		method: 'post',
		postBody: $('login_form2').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('login_loading2').hide();	
		   $('login_result2').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function checkLostPw() {
	$('lostpw_loading').show();
	new Ajax.Request('ajax/lostpw.php',
	{
		method: 'post',
		postBody: $('lostpw_form').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('lostpw_loading').hide();	
		   $('lostpw_result').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

//Bildanzeigen
function displayBild(w,h,img,titel) {
	showGrayBox();
	new Ajax.Request('modules_gb/bild.php',
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		parameters: "w="+w+"&h="+h+"&img="+img+"&titel="+titel,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

//Bestellung anzeigen
function displayOrders(ident,title) {
	showGrayBox();
	new Ajax.Request('modules_gb/orders.php',
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		parameters: "ident="+ident+"&title="+title,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function empfehlen(ident,qrystring){
	showGrayBox();
	new Ajax.Request('ajax/empfehlen.php',
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		parameters: "ident="+ident+"&qstring="+qrystring,
		onComplete: function(t) {
			$('gray_box_content').update(t.responseText);
			center('gray_box');
		},
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}



function sendempfehlen() {
	//$('loading').show();
	new Ajax.Request('ajax/empfehlen.php',
	{
		method: 'post',
		postBody: $('empfehlen_form').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		  // $('loading').hide();	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function reorder(ident){
	new Ajax.Request('ajax/reorder.php',
		{
			method: 'get',
			asynchronous: true,
			evalScript: true,
			parameters: "ident="+ident,
			onComplete: function(t) {
				showGrayBox();
				$('gray_box_content').update(t.responseText);
				center('gray_box');
			},
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}		
		}
	);
}

var newkat;
var opts;

function changeKat(newkat,opts){
	window.setTimeout("document.location.href='index.php?kat="+newkat+"&"+opts+"';",5);	
}

Xoffset=10;   // modify these values to ...
Yoffset=10;    // change the popup position.
var x = 0;
var y = 0;
document.onmousemove=get_mouse;
	
function popup(text){
	if(text != '') {
		var content= "<table border='0' cellspacing='0' cellpadding='2'><tr><td>"+text+"</td></tr></table>";
		$('hoverdiv').innerHTML=content;
		$('hoverdiv').style.left=(x+Xoffset)+"px";
		$('hoverdiv').style.top=(y+Yoffset)+"px";
		$('hoverdiv').show();
	}
}

function sitemapPopup(kat){
	$('hoverdiv').show();
	$('hoverdiv').innerHTML="<table border='0' cellspacing='0' cellpadding='2'><tr><td><img src='images/loading_small2.gif' /></td></tr></table>";
	
	$('hoverdiv').style.left=(x+Xoffset)+"px";
	$('hoverdiv').style.top=(y+Yoffset)+"px";
	
	new Ajax.Request('ajax/sitemap.php?file='+kat,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('hoverdiv').update("<table border='0' cellspacing='0' cellpadding='2' width='300'><tr><td style='width: 300px;font-size: 11px;'>"+t.responseText+"</td></tr></table>");
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function avPopup(id) {
	$('avdiv').show();
	$('avdiv').innerHTML="<table border='0' cellspacing='0' cellpadding='2'><tr><td><img src='images/loading_small2.gif' /></td></tr></table>";
	
	$('avdiv').style.left=(x+Xoffset)+"px";
	$('avdiv').style.top=(y+Yoffset)+"px";
	new Ajax.Request('ajax/av_warenangebot.php?id='+id,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
			res = t.responseText.split("|");
			
			ausgabe = "<table border='0' cellspacing='0' cellpadding='2' width='300'><tr><td><b>"+res[2]+"</b></td></tr>" +
			"<tr><td>"+ res[0] + " "+ res[1] + "</td></tr></table>";
		  	$('avdiv').update(ausgabe);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function setAVPosition() {
	$('avdiv').style.left=(x+Xoffset)+"px";
	$('avdiv').style.top=(y+Yoffset)+"px";	
}
	
function get_mouse(e){
	if(!e) e = window.event;
	x = e.clientX+document.documentElement.scrollLeft;
	//	if (document.documentElement.scrollTop!=0) alert(document.documentElement.scrollTop );
    y = e.clientY+document.documentElement.scrollTop ;
}
function kill(){
	$('hoverdiv').hide();
	$('avdiv').hide();	
}
	
function customCursor(img) {	
	var objBody = document.getElementsByTagName( 'body' ).item( 0 );
	
	if($('custom_cursor')) {
		$('custom_cursor').show();
		$('custom_cursor').style.left = x + "px";
		$('custom_cursor').style.top = y + "px";
	} else {
		var customc = document.createElement("div");
		
		customc.setAttribute('id', 'custom_cursor');
		
		customc.innerHTML = "<img src='"+img+"' border='0' />";
		
		customc.style.position = "absolute";
		customc.style.left = x + "px";
		customc.style.top = y + "px";
		
		objBody.appendChild(customc);
	}
	
}

function killCursor() {
	if($('custom_cursor')) $('custom_cursor').hide();
}
	
selectBox = function(selectName,boxWidth,boxHeight) {

    /*
    **     selectbox v0.0.0.0.7.3pre-alpha rev. 0.5cvs
    **     © 2007 christian kaiser
    */


    // Eigenschaften
    //

    var staticFontSize        = new Number(12);        // Textfeld Schriftgröße
    var staticFontFace        = new String("arial");        // Textfeld Schriftart
    var staticBorderColor     = new String("#979797");    // Textfeld Rahmenfarbe

    var imageWidth            = new Number(19);
    var img_up_mout           = new String("images/up.gif");        // image up-scroll mouseout
    var img_up_mover          = new String("images/up2.gif");    // image up-scroll mouseover
    var img_down_mout         = new String("images/down.gif");    // image down-scroll mouseout
    var img_down_mover        = new String("images/down2.gif");    // image down-scroll mouseover
    
    var output          = new String();
    var spanRandId      = new String(Math.floor(Math.random()*10000000));
    var selectRandId    = new String(Math.floor(Math.random()*10000000));
    var imagesRandId    = new String(Math.floor(Math.random()*10000000));

    
    output += "<table cellspacing='0px' cellpadding='0px'>";
    output += "<tr>";
    output += "<td rowspan='2'>";
    output += "<span id='"+spanRandId+"'>";
    output += "<input type='text' style='";
    output += "width:"+(boxWidth-imageWidth)+"px;";
    output += "font:"+staticFontSize+"px "+staticFontFace+";";
    output += "border:1px solid "+staticBorderColor+";";
    output += "height:"+boxHeight+"px;cursor:default' ";
    output += "id='_"+selectRandId+"_1' readonly>";
    output += "<input type='hidden' id='_"+selectRandId+"_2' name='"+selectName+"'>";
    output += "</span>";
    output += "</td>";
    output += "<td valign='bottom'>";
    output += "<img src='"+img_up_mout+"' name='"+imagesRandId+"_1' ";
    output += "onmouseover=\"this.src='"+img_up_mover+"'\" ";
    output += "onmouseout=\"this.src='"+img_up_mout+"'\" ";
    output += "onclick=\"document.getElementById('"+spanRandId+"').setLower()\">";
    output += "</td>";
    output += "</tr>";
    output += "<tr>";
    output += "<td valign='top'>";
    output += "<img src='"+img_down_mout+"' name='"+imagesRandId+"_2' ";
    output += "onmouseover=\"this.src='"+img_down_mover+"'\" ";
    output += "onmouseout=\"this.src='"+img_down_mout+"'\" ";
    output += "onclick=\"document.getElementById('"+spanRandId+"').setUpper()\">";
    output += "</td>";
    output += "</tr>";
    output += "</table>";

    document.write(output);

    var obj               = document.getElementById(spanRandId);
    obj.selectedIndex     = 0;
    obj.spanRandId        = spanRandId;
    obj.selectLable       = new Array();
    obj.selectValue       = new Array();
    obj.valueBoxId        = document.getElementById("_"+selectRandId+"_1");
    obj.optionBoxId       = document.getElementById("_"+selectRandId+"_2");

    obj.setValues = function() {
        this.valueBoxId.value  = this.selectLable[this.selectedIndex];
        this.optionBoxId.value = this.selectValue[this.selectedIndex];
    }

    obj.setUpper = function() {
        if(this.selectedIndex<this.selectLable.length-1) {
            this.selectedIndex++;
            this.setValues();
        }
    };

    obj.setLower = function() {
        if(this.selectedIndex>0) {
            this.selectedIndex--;
            this.setValues();
        }
    };

    this.prototype = obj;
    this.addValues = function(lable,value) {

        var p = this.prototype;

        p.selectLable[p.selectLable.length] = lable;
        p.selectValue[p.selectValue.length] = value;

        p.valueBoxId.value  = p.selectLable[0];
        p.optionBoxId.value = p.selectValue[0];

        p = undefined;
    };

    obj                  = undefined;
    output               = undefined;
    spanRandId           = undefined; 
    selectRandId         = undefined;
    imagesRandId         = undefined;
    
    staticFontSize       = undefined;
    staticFontFace       = undefined;
    staticBorderColor    = undefined;

    imageWidth           = undefined;
    img_up_mout          = undefined;
    img_up_mover         = undefined;
    img_down_mout        = undefined;
    img_down_mover       = undefined;
};

//var detail_view=false;

function detail(img,cur,total,gi){
	showGrayBox();
	if(typeof gi == "undefined") var gi="false";
	new Ajax.Request('ajax/gallery_detail.php?i='+img+'&cur='+cur+'&total='+total+'&gi='+gi,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		   //window.setTimeout("",400);
		 //  detail_view=true;
		   //window.setTimeout("center('gray_box');", 500);
		   //window.setTimeout("center('gray_box');",1500);
		  // window.setTimeout("center('gray_box');",2500);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function detail2(img,cur,total,gi){
	showGrayBox2();
	if(typeof gi == "undefined") var gi="false";
	new Ajax.Request('ajax/gallery_detail.php?gb=2&i='+img+'&cur='+cur+'&total='+total+'&gi='+gi,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content2').update(t.responseText);
		   center('gray_box2');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function detail3(img,cur,total,gi){
	showGrayBox2();
	if(typeof gi == "undefined") var gi="false";
	new Ajax.Request('ajax/gallery_detail.php?gb=3&i='+img+'&cur='+cur+'&total='+total+'&gi='+gi,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content2').update(t.responseText);
		   center('gray_box2');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function videodetail(video,cur,total,vgi){
	showGrayBox();
	if(typeof vgi == "undefined") var vgi="false";
	new Ajax.Request('ajax/videogallery_detail.php?i='+video+'&cur='+cur+'&total='+total+'&vgi='+vgi,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		   //window.setTimeout("",400);
		 //  detail_view=true;
		   //window.setTimeout("center('gray_box');", 500);
		   //window.setTimeout("center('gray_box');",1500);
		  // window.setTimeout("center('gray_box');",2500);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function languageBox(qrystring){
	showGrayBox();
	new Ajax.Request('ajax/languages.php?'+qrystring,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		   //window.setTimeout("",400);
		 //  detail_view=true;
		   //window.setTimeout("center('gray_box');", 500);
		   //window.setTimeout("center('gray_box');",1500);
		  // window.setTimeout("center('gray_box');",2500);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function getInhalt(start,kat) {
//alert(start + " " + kat);
//return;
	if($('loading'))	$('loading').show();
	//else alert('loading gibts nicht');
	new Ajax.Request('ajax/normal.php?kat='+kat+'&start='+start,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {
		   $('loading').hide();
		   $('maincontent').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function getSuche(start) {
	if($('loading'))	$('loading').show();
	//alert('suche='+$('letzte_suche').value+'&start='+start);
	new Ajax.Request('ajax/suche.php',
	{
	
		method: 'post',
		asynchronous: true,
		evalScript: true,
		postBody: 'suche='+$('letzte_suche').value+'&start='+start,
		
		onComplete: function(t) {
		   $('loading').hide();	
		   $('maincontent').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function moveXbySlicePos (x, img) { 
	if (!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
			if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
			if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}
	} else if (img.x) x += img.x;
	return x;
}

function moveYbySlicePos (y, img) {
	if(!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
			if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
			if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}		
	} else if (img.y >= 0) y += img.y;
	return y;
}


var mousovermenu = false;
	
function openNavi(id) {;
	
	for(i = 1; i <= 99; i++) {
		if($('topsubnavi_'+i)) {
			$('topsubnavi_'+i).style.display = 'none';
		}
	}
	
	if($('topsubnavi_'+id)) {
		xpos = moveXbySlicePos(-3, $('topnavi_'+id));
		ypos = moveYbySlicePos(20, $('topnavi_'+id));
		$('topsubnavi_'+id).style.top = ypos+"px";
		$('topsubnavi_'+id).style.left = xpos+"px";
		//alert(xpos+" - "+ypos + " || "+$('subnavi_'+id).style.left + " - "+$('subnavi_'+id).style.top);
		$('topsubnavi_'+id).style.position = 'absolute';
		$('topsubnavi_'+id).style.display = 'block';
	
		mouseovermenu = true;
		hideSelect();
	}
}

function hideNavi(id) {
	mouseovermenu = false;
	setTimeout("hideIt('"+id+"');", 1000);
}

function hideIt(id) {		
	if(mouseovermenu != true) {
		if($('topsubnavi_'+id)) $('topsubnavi_'+id).style.display = 'none';
		showSelect();
	}
}

function moTrue() {
	mouseovermenu = true;
}

function unterkunft(id,a,b) {
	Effect.toggle('unterkunft_'+id,'blind');
	if($('unterkunft_link_'+id).innerHTML == a) {
		$('unterkunft_link_'+id).innerHTML = b;
	} else {
		$('unterkunft_link_'+id).innerHTML = a;
	}
	
	setTimeout("new Effect.ScrollTo('unterkunft_'+"+id+");", 1000);	
}

function showUnterkunft() {
	$('unterkunft_response').update('<center><img src="images/loading_small2.gif" /><img src="images/loading_font.gif" /></center>');
	new Ajax.Request('ajax/unterkunft.php',
	{
		method: 'post',
		postBody: $('unterkunft_form').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('unterkunft_response').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function showMesseplan(halle){
	if(showMesseplan.arguments.length > 1) {
		halle = halle + "&back=true";
	}
	
	if(halle != "") {
		showGrayBox();
		new Ajax.Request('modules_gb/messestand.php?halle='+halle,
		{
			method: 'get',
			asynchronous: true,
			evalScript: true,
			onComplete: function(t) {	
			   $('gray_box_content').update(t.responseText);
			   center('gray_box');
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}		
		}
		);
	}
}

function warenangebot(id,anzahl,start,spalte,richtung){	
	$('angebote_loading').show();
	
	new Ajax.Request('ajax/warenangebot.php?aid='+id+'&anzahl='+anzahl+'&start='+start+'&spalte='+spalte+'&richtung='+richtung,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   	$('angebote').update(t.responseText);
		  	$('angebote_loading').hide();
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);	
}

function ausstellerDetails(id){
	showGrayBox();
	new Ajax.Request('modules_gb/ausstellerdetails.php?id='+id,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}
function multiFavorites(staende){
	var pbdy="&add_favs="+staende;
	new Ajax.Request('ajax/favoriten.php?1=1',
	{
		method: 'post',
		postBody: pbdy,
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('ajax_post_layer').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);	
}

function markChkBoxes(name){
	var boxes=document.getElementsByName(name);
	for(var mcb=0;mcb<boxes.length;mcb++){
		if(boxes[mcb].checked) {}
		else boxes[mcb].checked=true;
	}
}

function addFavorites(favform,clicked){
	// ajax_post_layer
	var favs=document.getElementsByName('favoriten[]');
	var pbdy="";
	for(var fi=0;fi<favs.length;fi++){
		// favoriten manuell serializen...
		if(favs[fi].checked) pbdy+="&favoriten%5B%5D="+favs[fi].value;
	}
	//alert(pbby);
	//alert($(favform).length);
	new Ajax.Request('ajax/favoriten.php?clicked='+clicked,
	{
		method: 'post',
		postBody: pbdy,
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('ajax_post_layer').update(t.responseText);
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);	
}

function deleteFavorites(question) {
	
	if(window.confirm(question)) {
		new Ajax.Request('ajax/favoriten.php?delete=all',
		{
			method: 'get',
			asynchronous: true,
			evalScript: true,
			onComplete: function(t) {	
			   $('ajax_post_layer').update(t.responseText);
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}		
		}
		);	
		
		checkboxen = document.getElementsByTagName( 'input' );
		for ( i = 0; i != checkboxen.length; i++ )
		{
			if(checkboxen[i].name == "favoriten[]") {
				checkboxen[i].checked = false;
			}
		}
	}
}

function printFavorites(ftyp){

	if(!ftyp){
		hideGrayBox();
		showGrayBox();
		$('gray_box_content').update("<div align='left'><br>Bitte w&auml;hlen Sie eine Druckansicht aus:<br><br><br><img src='images/icons/liste_detail.gif' onClick=\"printFavorites('extended');\" style='cursor:pointer;'>&nbsp;&nbsp;&nbsp;<img src='images/icons/kartenansicht.gif' onClick=\"printFavorites('map');\" style='cursor:pointer;'><br>&nbsp;</div>");
		center('gray_box');	
	}
	else {
	
/*	new Ajax.Request('modules_gb/ausstellerdetails.php?id='+id,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	*/
			window.open('print_favoriten.php?typ='+ftyp,'','width=800,height=600,scrollbars=yes');
			/*
			if(ie) {
				window.open('print_favoriten.php?typ='+ftyp,'','width=800,height=600,scrollbars=yes');
			} else {
		   		$('hiddenFrame').src='print_favoriten.php?typ='+ftyp;
			}
			*/
		}
	/*	},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);*/
}

function updateZeichen() {
	$('speziellesAngebot').value = $('speziellesAngebot').value.substr(0,250);
	$('zeichen').innerHTML = $('speziellesAngebot').value.length;
}

//Bannertausch
function deleteBanner(id,question) {
	if(window.confirm(question)){
		new Ajax.Request('bannerupload.php?action=delete&user='+id,
		{
			method: 'get',
			asynchronous: true,
			evalScript: true,
			onComplete: function(t) {	
			   openBannertausch();
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}		
		}
		);
	}
}


function switchProfil(jahr,jahre){
	if($('profil_div_aktuell')) $('profil_div_aktuell').hide();
	if($('profil_register_aktuell')) $('profil_register_aktuell').className="aussteller_register_inaktiv";
	var jre=jahre.split(",");
	//alert(jre);
	for(j=0;j<jre.length;j++){
		jr=jre[j];
		if($('profil_div_'+jr)) $('profil_div_'+jr).hide();
		if($('profil_register_'+jr)) $('profil_register_'+jr).className="aussteller_register_inaktiv";
	}
	if($('profil_div_'+jahr)) $('profil_div_'+jahr).show();
	if($('profil_register_'+jahr)) $('profil_register_'+jahr).className="aussteller_register_aktiv";
	else alert(jahr+" wurde nicht gefunden.");
}

function dsplThumbnails(id){
	showGrayBox();
	new Ajax.Request('modules_gb/thumbnailgallery.php?id='+id,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content').update(t.responseText);
		   center('gray_box');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function fotoGallaAtMeinProfil(picture, akk_nr, max_nr){
	var preNr  = akk_nr - 1
	var nextNr = akk_nr + 1;
	if(preNr<1)preNr=1;
	if(nextNr>max_nr)nextNr=max_nr;
	
	var prev = "javascript:fotoGallaAtMeinProfil('"+picture+"',"+(preNr)+", "+max_nr+");";
	var next = "javascript:fotoGallaAtMeinProfil('"+picture+"',"+(nextNr)+", "+max_nr+");";
	var ret = '<div style="text-align:center;padding-bottom:5px;padding-top:5px;">';
	ret += '<a class="black" href="'+prev+'">&lt;&lt;</a> Bild '+akk_nr+' von '+max_nr+' <a class="black" href="'+next+'">&gt;&gt;</a>';
	ret += '</div>';
	ret += '<img src="'+picture+'-'+akk_nr+'.JPG" width="450" style="padding-left:80px;" />';
		
	$("standBilder").update(ret);
}

function fotoGallaAtMeinProfil_dsplThumbnails(picture, max_nr){
	showGrayBox3();
	new Ajax.Request('modules_gb/thumbnailgallery.php?picture='+picture+'&max_nr='+max_nr,{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content3').update(t.responseText);
		   center('gray_box3');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	});
}



function selectAllThubmnails() {
	el = document.getElementsByClassName("psCheckbox");
	
	for(i = 0; i < el.length; i++) {
		if($(document.getElementsByClassName("psCheckbox")[i])) $(document.getElementsByClassName("psCheckbox")[i]).checked = true;
	}
}
function unselectAllThubmnails() {
	el = document.getElementsByClassName("psCheckbox");
	
	for(i = 0; i < el.length; i++) {
		if($(document.getElementsByClassName("psCheckbox")[i])) $(document.getElementsByClassName("psCheckbox")[i]).checked = false;
	}
}

function createArchive() {
	$('thumbs_loading').show();
	new Ajax.Request('ajax/createzip.php',
	{
		method: 'post',
		postBody: $('thumbsform').serialize(),
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('thumbs_res').update(t.responseText);
		   $('thumbs_loading').hide();
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}

function austellerDetailsHallenplan(halle,stand){
	showGrayBox2();
	new Ajax.Request('modules_gb/messestand.php?halle='+halle+'&stand='+stand,
	{
		method: 'get',
		asynchronous: true,
		evalScript: true,
		onComplete: function(t) {	
		   $('gray_box_content2').update(t.responseText);
		   center('gray_box2');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}		
	}
	);
}