	var myWin = null;

	function openWin(x,y,url)
	{
		var width			= x;
		var height		 = y;
		var page			 = url.toString();
		var options		= "resizable=1,width="+width.toString();
				options	 += ",height="+height.toString();
		var leftborder = Math.ceil((screen.availWidth-width)/2);
		var topborder	= Math.ceil((screen.availHeight-height)/2);
				options	 += ",left="+leftborder.toString();
				options	 += ",top="+topborder.toString();
				options	 += ",scrollbars=1";

		// convert popup urls for babelfish
		if (!page.match('http://') && location.href.match('babelfish\.altavista\.com'))
		{
			var lang = location.href.match('lp=de_([a-z]{2})');
			if (lang)
				page = 'http://babelfish.altavista.com/babelfish/trurl_pagecontent?lp=de_'
					+lang[1]+'&url=http%3A%2F%2Fwww.egun.de%2Fmarket%2F'+encodeURI(page);
		}

		window.open(page,"myWin",options).focus();
	}

	function closeWin()
	{
		if (myWin != null)
			if (!myWin.closed)
				myWin.close();
	}

	function createHIF(ident)
	{
		var el;
		el=document.getElementById('HIF'+ident);
		if (!el)
		{
			el = document.createElement('iframe');
			el.id = 'HIF'+ident;
			el.style.width=1; el.style.height=1; el.style.display = 'none';
			el.src = 'about:blank;';
			document.getElementById('stime').parentNode.appendChild(el);
		}
		return el;
	}

	var timediff = 0, aucEndsUTime=0, lastSync=0, clockIV=0;
	function timedisplay()
	{
		var curtime = new Date(), stamp;
		stamp = curtime.getTime();
		if (!lastSync || lastSync<stamp-300000) { lastSync=stamp; createHIF('clocksync').src='clocksync.js.php?'+stamp; }
		curtime.setTime(stamp + timediff);
		document.getElementById('stime').innerHTML=
//	window.status =
			curtime.toLocaleString();
	}
	function timeinit(servertime)
	{
		clienttime = new Date();
		lastSync = clienttime.getTime();
		timediff = servertime-lastSync;
		if (!clockIV)
		{
			timedisplay();
			clockIV = window.setInterval('timedisplay()', 1000);
		}
	}

	function intval(string)
	{
		var i, c, v=0;
		for (i=0; i<string.length; i++)
		{
			c = string.substr(i, 1);
			if ('0'>c || '9'<c)
				break;
			v = v*10 + parseInt(c);
		}
		return v;
	}

	function getpos(el)
	{
		var e=el,tagname="",x=0,y=0;
		while ((typeof(e)=="object")&&(typeof(e.tagName)!="undefined"))
		{
			y+=e.offsetTop; x+=e.offsetLeft;
			tagname=e.tagName.toUpperCase();
			if (tagname=="BODY") e=0;
			if (typeof(e)=="object") if (typeof(e.offsetParent)=="object") e=e.offsetParent;
		}
		position=new Object(); position.x=x; position.y=y; return position;
	}

	function confirm_clone()
	{
		return confirm('Wollen Sie wirklich einen ähnlichen Artikel einstellen und nicht diesen Artikel bearbeiten?');
	}

	// 2008-04-09: funky quick search
	// 2011-06/07: via jquery.autocomplete
	var qqFocused=false, qqHintValue='Artikel-ID oder Suchbegriff', qqDefaultLabel='';
	function complete_format(row)
	{
		if ( row !== undefined )
			return row[0];
	/*	{
			var size = ("N/A"==row.size || ""==row.size || null==row.size || "null"==row.size || undefined==row.size
				? "" : "["+row.size+"]");
			return row.itemNum+ ", ("+ row.extracode+ ") "+ row.brand+ " "+ row.shortDesc+ " "+ size;
		} */
		else
			return "No items...";
	}
	function complete_prepare(fieldId, acGroup)
	{
		if (!presets || !presets[acGroup])
		{
			if ('search'==acGroup && !ac_search) return;
			lazyload('./includes/autocomplete.'+
				('search'==acGroup ? (ac_search>1 ? 'search_full':'search')
					: (acGroup.match(/^mail_/) ? 'scext'
					: 'default'
				))+ '.js'
			);
		}
		if (presets[acGroup].length)
		{
			var el = document.getElementById(fieldId);
			$("#"+fieldId).autocomplete(presets[acGroup], {
				matchContains : 'word',
				width : el.offsetWidth,
				max : 50,
				scroll : true,
				min : (acGroup.match(/^mail_/)?0:1),
				formatItem : complete_format,
				selectFirst : false
			});
		}
	}

	var ac_search = 0;
	function qqHover()
	{
		var el = document.getElementById('qqLabel');
		if (!qqDefaultLabel)
			qqDefaultLabel = el.innerHTML;
		el.innerHTML = '';
		el = document.getElementById('qquery');
		el.style.width=186;
		if (ac_search)
			$("document").ready(complete_prepare('qquery', 'search'));
	}
	function qqUnHover()
	{
		if (!qqFocused)
		{
			var el = document.getElementById('qquery');
			el.style.width = 120;
			if (qqDefaultLabel)
				document.getElementById('qqLabel').innerHTML = qqDefaultLabel;
		}
	}
	function qqFocus()
	{
		el = document.getElementById('qquery');
		if (el.value==qqHintValue)
		{
			el.value = '';
			el.style.color='black';
		}
		qqFocused = true;
		qqHover();
	}
	function qqBlur()
	{
		el = document.getElementById('qquery');
		if (!el.value.length || el.value==qqHintValue)
		{
			el.style.color = '#999999';
			el.value = qqHintValue;
		}
		qqFocused = false;
		qqUnHover();
//	if (document.readyState == "complete") complete_blur();
	}

	var lazyloaded= { 'window.js' : true };

	function lazyload(filename)
	{
		if (lazyloaded[filename]) return true;
		var req = false;
		if (typeof XMLHttpRequest != 'undefined') { req = new XMLHttpRequest(); }
		if (!req)
		{
			try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
			catch(e)
			{
				try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
				catch(e) { req = null; }
			}
		}
		// Vorbereiten des Requests:
		req.open('get', filename, false);
		req.send(null);
		if (lazyloaded[filename] = (4==req.readyState))
		{
			if (window.execScript) { window.execScript(req.responseText); }
			else { eval(req.responseText); }
		} else {
			alert("Request fehlgeschlagen!");
		}
		return lazyloaded[filename];
	}
