var isHiding = false;
var pageIsLoaded = false;
var tmp_container = document.createElement("div");

function resizeWindow() {
	var height = window.innerHeight;
	if (height > 574) {
		height = (height  - 574) / 2;
		document.getElementById('main_wrap').style.top = height + 'px';
	} else {
		document.getElementById('main_wrap').style.top = '0px';
	}
}

function hide_all() {
	for (var i=0;i<=nav_row_anz;i++) {
		document.getElementById('r'+i+'_c2').style.display='none';

		var cur_elem = document.getElementById('m'+i);
		var Suche = /_aktiv$/i;
		var Ergebnis = Suche.test(cur_elem.className);
		//alert(cur_elem.className);
		if (Ergebnis == false) {
			cur_elem.style.backgroundColor='#3a3b35';
			cur_elem.style.color='#d8d8d8';
		}
	}

	for (i=0;i<kol_ber.length;i++) {
		if (document.getElementById('k'+kol_ber[i])) document.getElementById('k'+kol_ber[i]).style.display='none';
		if (document.getElementById('c'+kol_ber[i])) document.getElementById('c'+kol_ber[i]).style.backgroundColor='#3a3b35';
		if (document.getElementById('c'+kol_ber[i])) document.getElementById('c'+kol_ber[i]).style.color='#d8d8d8';
	}
}

function sc_h( col ) {
	for (var i=0;i<=nav_row_anz;i++) {
		document.getElementById('r'+i+'_c2').style.display='none';

		var cur_elem = document.getElementById('m'+i);
		var Suche = /_aktiv$/i;
		var Ergebnis = Suche.test(cur_elem.className);
		//alert(cur_elem.className);
		if (Ergebnis == false) {
			cur_elem.style.backgroundColor='#3A3B35';
			cur_elem.style.color='#D8D8D8';
		}
	}

	for (i=0;i<kol_ber.length;i++) {
		if (document.getElementById('k'+kol_ber[i])) document.getElementById('k'+kol_ber[i]).style.display='none';
		if (document.getElementById('c'+kol_ber[i])) document.getElementById('c'+kol_ber[i]).style.backgroundColor='#3A3B35';
		if (document.getElementById('c'+kol_ber[i])) document.getElementById('c'+kol_ber[i]).style.color='#D8D8D8';
	}

	document.getElementById('r'+col+'_c2').style.display='block';
	document.getElementById('m'+col).style.backgroundColor='#D8D8D8';
	document.getElementById('m'+col).style.color='#3A3B35';

}
function sc_o( col ) {
	document.getElementById(col).style.visibility='hidden';
}

function cL_h( col ) {
	for (var i=1;i<=5;i++) {
		if (document.getElementById('r3_c3_L'+i))
			document.getElementById('r3_c3_L'+i).style.display='none';
	}
	document.getElementById(col).style.display='block';
	//alert(document.getElementById(col));
}

function sk_h ( kol, farbe ) {
	if (!farbe) farbe = '#d8d8d8';
	//alert(kol);
	for (var i=0;i<kol_ber.length;i++) {
		if (document.getElementById('k'+kol_ber[i])) document.getElementById('k'+kol_ber[i]).style.display='none';
	}

	var to_hide = $('box_nav_wrap').getElementsByClassName("submenu_link");

	for (var i=0; i<to_hide.length; i++) {
		to_hide[i].style.backgroundColor='#3A3B35';
		to_hide[i].style.color='#d8d8d8';
	}

	if (document.getElementById('k'+kol)) document.getElementById('k'+kol).style.display='block';
	//document.getElementById('k'+kol).style.display='block';
	if (document.getElementById('c'+kol)) document.getElementById('c'+kol).style.backgroundColor=farbe;
	if (document.getElementById('c'+kol) && farbe == '#d8d8d8') document.getElementById('c'+kol).style.color='#3A3B35';

	//if (document.getElementById('k'+kol)) Effect.Appear('k'+kol, { duration: 0.2 });
}

function sd_h ( row, kol, color ) {
	//alert('k'+row);
	row_elements = $('k'+row).getElementsByClassName('k'+row);
	//alert(row_elements.length);

	for (i=0;i<row_elements.length;i++) {
		elem = row_elements[i].next();
		//alert(row_elements[i].up().inspect());
		elem.style.display='none';
		row_elements[i].up().style.backgroundColor='#3A3B35';
		row_elements[i].style.backgroundColor='#3A3B35';
		row_elements[i].style.color='#d8d8d8';
	}

	row_elements = $('k'+row).getElementsByClassName('k'+row+'_aktiv');
	//alert(row_elements.length);

	for (i=0;i<row_elements.length;i++) {
		row_elements[i].next().style.display='none';
		row_elements[i].up().style.backgroundColor='#3A3B35';
		row_elements[i].style.backgroundColor='#3A3B35';
		row_elements[i].style.color='#d8d8d8';
	}

	document.getElementById('kb'+kol).style.display='inline';
	document.getElementById('kb'+kol).previous().style.backgroundColor='#d8d8d8';
	document.getElementById('kb'+kol).previous().style.color='#3A3B35';
	//document.getElementById('kb'+kol).style.display='inline';
	//document.getElementById('kb').style.display='none';
}

var new_img = null;

function showImage (new_src) {

	if ($('produkt_bild').src != new_src) {
		isLoading = true;
		showLoader();
		$('produkt_bild').src = new_src;

		$('produkt_bild').onload = function () {
			isLoading = false;
			hideLoader();
		}
	}
}


// Maus-Position abfragen

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXYLoader(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY

  $('loader').style.left = (tempX+20) + "px";
  $('loader').style.top = (tempY+5) + "px";

  return true
}

var isLoading = true;

function showLoader() {
	document.onmousemove = getMouseXYLoader;
	window.setTimeout('doShowLoader()', 50);
}

function doShowLoader() {
	if (isLoading) $('loader').show();
}

function hideLoader() {
	$('loader').hide();
	document.onmousemove = null;
}


var gal_pos = 0;
var gal_interval = false;
var cur_gal_anz = 0;
function showGalerie (bg_color, anz) {
	$('overlay').style.backgroundColor = bg_color;

	if (anz > 3) {
		myLightbox.start($('img0'), true);
	}
	else myLightbox.start($('img0'), false);

}

function showGalerieNext() {
	gal_pos++;

	if (cur_gal_anz > gal_pos) {
		myLightbox.changeImage(gal_pos);
	}
	else clearInterval(gal_interval);

}

window.onload = function() {
	pageIsLoaded = true;
	Event.observe('box_nav_wrap', 'click', function(e){ hideMenuDelay() });
	if ($('produkt_col3')) Event.observe('row_content', 'click', function(e){ hideImgInfo() });
}

function hideMenuDelay() {
	window.setTimeout('hide_all()', 100);
}

function imgInfo( titel, img ) {

	if (titel.length > 0) {
		var pos = Position.cumulativeOffset(img);

		$('imgInfo').down().innerHTML = titel;
		$('imgInfo').style.top = (pos[1]-21) + "px";
		$('imgInfo').style.left = (pos[0]+1) + "px";
		$('imgInfo').show();

		img.onmouseout = function () {
			$('imgInfo').hide();
			this.onmouseout = null;
		}
	}
}

function imgInfoD( titel, img ) {
	var pos = Position.cumulativeOffset(img);

	$('imgInfo').down().innerHTML = titel;
	var dimensions = $('imgInfo').getDimensions();
	//alert(dimensions.width);
	$('imgInfo').style.top = (pos[1]-21) + "px";
	$('imgInfo').style.left = (pos[0]-(dimensions.width/2)+15) + "px";
	$('imgInfo').show();

	img.onmouseout = function () {
		window.setTimeout('$(\'imgInfo\').hide()', 1000);
	}
}

function hideImgInfo() {
	$('imgInfo').hide();
}

function imgInfoB( medium_id, img ) {

	if (medium_id > 0) {
		var pos = Position.cumulativeOffset(img);

		$('imgInfo').down().innerHTML = $('ih'+medium_id).innerHTML;
		$('imgInfo').style.top = (pos[1]+30) + "px";
		$('imgInfo').style.left = (pos[0]+1) + "px";
		$('imgInfo').show();

		img.onmouseout = function () {
			$('imgInfo').hide();
			this.onmouseout = null;
		}
	}
}


function merken( pr_name, inh_id ) {
	url = web_dir + 'ajax.php?'+sess_str+'&do=merken&inh_id='+inh_id;

	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {

	  }
	});

	imgInfoD( pr_name + ' ' + msgMarkComplete, $('merken_bt') );
}

var to_hide = -1;
function merkzettel_loeschen( inh_id ) {
	to_hide = inh_id;
	url = web_dir + 'ajax.php?'+sess_str+'&do=loeschen&inh_id='+inh_id;
	$('p'+inh_id).hide();
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {

	  }
	});

}

function merkzettel_ansehen( inh_id ) {
	url = web_dir + 'ajax.php?'+sess_str+'&do=merzettel_abrufen';
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
		//alert(transport.responseText);
	  }
	});
}

function afterSelect( elem ) {

	url = web_dir + 'ajax.php?'+sess_str+'&do=haendler_zeigen';

	var s111 = $('s111').checked ? 1 : 0;
	var s112 = $('s112').checked ? 1 : 0;
	var s211 = $('s211').checked ? 1 : 0;
	var s212 = $('s212').checked ? 1 : 0;
	var s214 = $('s214').checked ? 1 : 0;
	var s311 = $('s311').checked ? 1 : 0;
	var s312 = $('s312').checked ? 1 : 0;
	var s313 = $('s313').checked ? 1 : 0;
	params = 'qry='+encodeURIComponent(elem.value)+"&s111="+s111+"&s112="+s112+"&s211="+s211+"&s212="+s212+"&s214="+s214+"&s311="+s311+"&s312="+s312+"&s313="+s313;

	new Ajax.Request(url, {
	  method: 'post',
	  parameters: params,
	  encoding: 'iso-8859-1',
	  onSuccess: function(transport) {
		$('indicator2').hide();
		$('feld_rechts').innerHTML = transport.responseText;
	  }
	});

	return false;
}

function selectElm( elem, han_id ) {
	//elem.toggleClassName('selected');
	//elem.style.backgroundColor = '#E9E9E9';
	elem.haendler_id = han_id;
	elem.onmouseout = function () {
		//elem.style.backgroundColor = '#FFFFFF';
		//this.toggleClassName('selected');
		//this.onclick = '';
		//this.onmouseout = '';
	}

	elem.onclick = function() {
		//this.toggleClassName('selected');
		//this.onmouseout = '';
		//elem.style.backgroundColor = '#FFFFFF';
		showHaendler( this.haendler_id );
	}
}

function showHaendler( han_id ) {
	url = web_dir + 'ajax.php?'+sess_str+'&do=haendler_zeigen_einzeln';
	params = 'han_id='+han_id;
	new Ajax.Request(url, {
	  method: 'post',
	  parameters: params,
	  encoding: 'iso-8859-1',
	  onSuccess: function(transport) {
	  	tmp_container.innerHTML = $('feld_rechts').innerHTML;

		$('feld_rechts').innerHTML = transport.responseText;
		//alert(transport.responseText);
	  }
	});
}

function showHaendlerName( ) {
	$('indicator2').show();
	url = web_dir + 'ajax.php?'+sess_str+'&do=haendler_zeigen_name';

	var s111 = $('s111').checked ? 1 : 0;
	var s112 = $('s112').checked ? 1 : 0;
	var s211 = $('s211').checked ? 1 : 0;
	var s212 = $('s212').checked ? 1 : 0;
	var s214 = $('s214').checked ? 1 : 0;
	var s311 = $('s311').checked ? 1 : 0;
	var s312 = $('s312').checked ? 1 : 0;
	var s313 = $('s313').checked ? 1 : 0;
	params = 'qry='+encodeURIComponent($('dealer_name').value)+"&s111="+s111+"&s112="+s112+"&s211="+s211+"&s212="+s212+"&s214="+s214+"&s311="+s311+"&s312="+s312+"&s313="+s313;
	
	if (params.length > 6) {
			new Ajax.Request(url, {
		  method: 'post',
		  parameters: params,
		  encoding: 'iso-8859-1',
		  onSuccess: function(transport) {
		  	tmp_container.innerHTML = $('feld_rechts').innerHTML;

			$('feld_rechts').innerHTML = transport.responseText;
			$('indicator2').hide();
			//alert(transport.responseText);
		  }
		});
	}
	else alert('Bitte min. 3 Zeichen eingeben!');

	return false;
}

function checkForm(  button ) {
	alert(button);

	return false;
}

function zeigeListe() {
	$('feld_rechts').innerHTML = tmp_container.innerHTML;
}
