var lastQuery	= "";
var xmlDoc		= null;
var timer		= null;

function jumpTo(params)
{
	var regex	= new RegExp("[\\?&]jumpTo=([^&#]*)");
	var results	= regex.exec(params);

	if (results != null)
	{
		location.hash = results[1];
	}
}

function toggleSearch(onOff)
{
	if (onOff == 1)
	{
		document.getElementById('topquery').value = '';
		timer = window.setInterval("quickSearch()", 1000);
	}
	else if (onOff == 0)
	{
		window.clearInterval(timer);
		setTimeout('toggleSearch(-1)', 1000);
	}
	else
	{
		document.getElementById('topquery').value					= 'Suchbegriff eingeben';
		document.getElementById('quickSearchResults').innerHTML		= '';
		document.getElementById('quickSearchLayer').style.display	= 'none';
	}
}

function quickSearch()
{
	var query = document.getElementById("topquery").value;
	
	if (query.length >= 3)
	{
		if (lastQuery != query)
		{
			lastQuery = query;
			sendSearch(query);
		}
	}
	else
	{
		document.getElementById("quickSearchLayer").style.display = "none";
		lastQuery = "";
	}
}

function sendSearch(query)
{
	if (typeof window.ActiveXObject != 'undefined')
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
		xmlDoc.onreadystatechange = process ;
	}
	else
	{
		xmlDoc = new XMLHttpRequest();
		xmlDoc.onload = process ;
	}
	xmlDoc.open("POST", url_search + '?query=' + query, true);
/*	xmlDoc.open("POST", url_search + '?query=' + query + '*', true); */
	xmlDoc.send(null);
}

function process()
{
	if (xmlDoc.readyState != 4) return;

        try {
	var response	= xmlDoc.responseText.replace(/(\r\n|\r|\n|\u0085|\u000C|\u2028|\u2029)/g, "").replace(/^ +/, "");
	var json    = eval('(' + response + ')');
	var results	= document.getElementById('quickSearchResults');

	if (json.hits > 0)
	{
		document.getElementById('quickSearchLayer').style.display = "";
		results.innerHTML = "";	

		for (i=0; i<json.hits; i++)
		{
			var style = "";
			
			if (json.data[i].type == 1005)		{ style = "vorlage"; }
			else if	(json.data[i].type == 1007)	{ style = "mustervorlage"; }
			else if	(json.data[i].type == 1010)	{ style = "broschuere"; }
			
			results.innerHTML += '<div class="layer_info_2col_1row">'
							  +  '<div class="layer_info_2col_1row_left"><a href="' + json.data[i].url + '" class="anc_layer_info_' + style + '">' + json.data[i].title + '</a></div>'
							  +  '<div class="layer_info_2col_1row_right">' + json.data[i].price + '</div>'
							  +  '</div>';

			if (json.hits > i + 1)
			{
				results.innerHTML += '<div class="layer_info_dots_bottom"></div>';
			}
			else
			{
				results.innerHTML += '<div class="layer_info_nodots_bottom"></div>';
			}
		}
	}
	else
	{
		document.getElementById("quickSearchLayer").style.display = 'none';
	}
        } catch(e) {}
}

function submitSearch(click)
{
	document.getElementById('topquery').value += '';
/*	document.getElementById('topquery').value += '*';*/
	if (click)
	{
		document.searchform.submit();
	}
	else
	{
		return true;
	}
}

function printMe(width)
{
	window.open(url_print + '?printVersion=auto', 'printPreview', 'width=' + width + ',height=750,scrollbars=yes');
}

function openWindow(url)
{
	window.open(url, 'popup', 'width=670,height=600,scrollbars=yes');
}


function setLevel3(value)
{
	var part = value.split("|");
	fillSelect(document.filter.level3, lvl3[part[0]]);
	document.filter.level4.length = 0;
	document.filter.level4.options[0] = new Option(unescape("<-- Bitte ausw%E4hlen"), "", false, false);
}

function setLevel4(value)
{
	var part = value.split("|");
	fillSelect(document.filter.level4, lvl4[part[0]]);
}

function fillSelect(select, options)
{
	select.length = 0;

	for (var i = 0; i < options.length; i++)
	{
		var option	= options[i].split("|");
		var last	= select.length;
		select.options[last] = new Option(option[2], option[0] + "|" + option[1], false, false);
	}
}

function submitFilter()
{
	for (var i = 4; i >= 2; i--)
	{
		var obj = document.filter.elements["level" + i];
		
		if (obj.selectedIndex > -1)
		{
			var url = obj.options[obj.selectedIndex].value.split("|");
			
			if (url[1] != "")
			{
				self.location.href = url[1];
				return true;
			}
		}
	}

	alert(unescape("Sie haben kein Dokument zum Aufrufen ausgew%E4hlt."));
}

var frames	= navigator.userAgent.search(/MSIE 6\.0/) == -1 ? 75 : 1;
var sizes	= new Array(new Array(148, 149, 149), new Array(148, 223, 75), new Array(75, 223, 148), new Array(75, 75, 296));

var bigBox	= 0;
var timer2	= 0;
var cron	= null;

function enlargeBox(id)
{
	bigBox	= id;
	timer2	= frames;

	if (cron == null)
	{
		cron = window.setInterval("updateWidth()", 20);
	}
}

function updateWidth()
{
	timer2--;

	for (var i=1; i<=3; i++)
	{
		var obj		= document.getElementById('filter_box_' + i);
		var width	= parseInt(obj.style.width, 10);
		var setTo	= sizes[bigBox][i-1];

		var newSize	= Math.round(setTo - (setTo - width) * timer2 / frames);

		if (obj.style.width != newSize)
		{
			obj.style.width = newSize + "px";
		}		
	}

	if (timer2 == 0)
	{
		window.clearInterval(cron);
		cron = null;
	}
}	
