var width = '';
var height = '';

var display = document.all ? 'inline' : 'table-row';

function client_info()
{
	if(navigator.appName == 'Netscape')
	{ 
		width = window.innerWidth;
		height = window.innerHeight;
	}
	else if (document.all)
	{
		width = document.body.clientWidth;
		height = document.body.clientHeight;
		
	}
	else if (document.layers) 
	{
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	}
	else
	{ 
		width = window.innerWidth;
		height = window.innerHeigth;
	}
	
	init_mousemove();
}

function showAGB()
{
	window_open('/texts/agb', '600', '700');
}

var open_popup = '';
function window_open(url)
{
	if(open_popup!='')
	{
		open_popup.close();	
		open_popup = '';
	}
	
	if(window_open.arguments[1])
	{
		if(window_open.arguments[1] == '100%')
		{
			var width = screen.width;	
		}
		else
		{
			var width = window_open.arguments[1];
		}
	}
	else
	{
		var width = 550;	
	}
	
	if(window_open.arguments[2])
	{
		if(window_open.arguments[2] == '100%')
		{
			var height = screen.height;	
		}
		else
		{
			var height = window_open.arguments[2];
		}
	}
	else
	{
		var height = 300;	
	}
	
	if(window_open.arguments[3])
	{
		var name = window_open.arguments[3];
	}
	else
	{
		var name = 'window';	
	}
	
	open_popup = window.open(url, name,'scrollbars=yes,resizable=yes,width='+width+',height='+height);
	open_popup.focus();
	return false;
}

var saved = '';

function printpage()
{
	if(document.getElementById('lang_content_id') && document.getElementById('lang_content_id').value != 0)
	{
		window_open('/print?lid='+document.getElementById('lang_content_id').value, 620, 600, 'print');
	}
	else
	{
		window_open('/print', 620, 600, 'print');
	}
}

function fix_tab(id)
{
	var checkelem = document.getElementById('tab_'+id);
	
	if(checkelem.style.display == 'none')
	{
		gonext('invisiblechange', "/xmlhttp/fixtab?stat=1");
	}
	else
	{
		gonext('invisiblechange', "/xmlhttp/fixtab?stat=0");
	}
}

function dynamichelp(id)
{
	var text = document.getElementById('hlp_'+id).value;
	if(dynamichelp.arguments[1])
	{
		document.getElementById('mouse_cursor').style.width = dynamichelp.arguments[1]+'px';
	}
	document.getElementById('mouse_cursor').style.display = 'inline';
	document.getElementById('mouse_cursor').innerHTML = text;
}

function hide_dynamichelp()
{
	document.getElementById('mouse_cursor').style.width = '';
	document.getElementById('mouse_cursor').style.display = 'none';
	document.getElementById('mouse_cursor').innerHTML = '&nbsp;';
}

var docEl = (
                 typeof document.compatMode != "undefined" && 
                 document.compatMode        != "BackCompat"
                )? "documentElement" : "body";

function init_mousemove()
{
        if(document.layers) document.captureEvents(Event.MOUSEMOVE);
        document.onmousemove =	dpl_mouse_pos;
}

function dpl_mouse_pos(e)
{
	var xPos    =  e? e.pageX : window.event.x;
        var yPos    =  e? e.pageY : window.event.y;
	
        if (document.all && !document.captureEvents)
	{
            xPos    += document[docEl].scrollLeft;
            yPos    += document[docEl].scrollTop;
        }
        
	if(typeof doWindowDrag == 'function')
	{
		doWindowDrag(e);
	}
	
	document.getElementById('mouse_cursor').style.position = "absolute";
	document.getElementById('mouse_cursor').style.left = 18+xPos+"px";
	document.getElementById('mouse_cursor').style.top = yPos+"px";
        
    if (document.layers) routeEvent(e);
}

function send_request(element, url)
{
	XMLcontent = element;
	xmlhttp = getxmlhttp();
	xmlhttp.open("get", url);
	xmlhttp.onreadystatechange = handleResponse;
	xmlhttp.send(null);
}

function gonext(element, url)
{
	if(GoToNext === true)
	{
		GoToNext = false;
		window.setTimeout('send_request(\''+element+'\', \''+url+'\');', 10);
	}
	else
	{
		window.setTimeout('gonext(\''+element+'\', \''+url+'\');', 50);
	}
}

var change_content = '';
var change_element = '';
function switch_values(obj, id)
{
	
	if(change_content=='')
	{
		change_element = obj;
		change_content = obj.innerHTML;
		obj.className = '';
		obj.innerHTML = document.getElementById('change_'+id).innerHTML;
	}
	else if(change_element != obj)
	{
		change_element.className = 'a';
		change_element.innerHTML = change_content;
		change_element = '';
		change_content = '';
		switch_values(obj, id);
	}
/*	change_element.style.left = (document.getElementById('mouse_cursor').style.left-10)+'px';
	change_element.style.top = (document.getElementById('mouse_cursor').style.top-3)+'px';
	change_element.style.position = 'absolute';
	change_element.style.zIndex = '99';
	change_element.style.display = 'inline';*/
}

function check_switch(obj, what)
{
	document.body.style.cursor = 'wait'; 
	document.getElementById(what+'_selection').value = obj.value;
	document.forms[what].submit();
}

function setCheckboxes (check_feld, do_check, check_feld2) 
{
	var elts = document.cart_quantity.elements[check_feld + '[]'];
	if (check_feld2 != '') var elts2 = document.cart_quantity.elements[check_feld2 + '[]'];
	var elts_cnt = (typeof(elts.length) != 'undefined') ? elts.length : 0;
	if (elts_cnt) {
		for (var i = 0; i < elts_cnt; i++) {
			elts[i].checked = do_check;
			if ((typeof(elts2) != 'undefined') && (elts2[i].checked == true)) elts2[i].checked = false;
		}
	} else {
		elts.checked = do_check;
		if ((typeof(elts2) != 'undefined') && (elts2.checked == true)) elts2.checked = false;
	}
	if (do_check) {
		if (check_feld == 'cart_delete') {
			window.document.getElementById('del_all_on').style.display = "none";
			window.document.getElementById('del_all_off').style.display = "inline";
			if (window.document.getElementById('order_all_off')) {
				window.document.getElementById('order_all_off').style.display = "none";
				window.document.getElementById('order_all_on').style.display = "inline";
			}
		} else {
			if (window.document.getElementById('order_all_off')) {
				window.document.getElementById('order_all_on').style.display = "none";
				window.document.getElementById('order_all_off').style.display = "inline";
			}
			window.document.getElementById('del_all_off').style.display = "none";
			window.document.getElementById('del_all_on').style.display = "inline";
		}
	} else {
		if (check_feld == 'cart_delete') {
			window.document.getElementById('del_all_off').style.display = "none";
			window.document.getElementById('del_all_on').style.display = "inline";
		} else if (window.document.getElementById('order_all_off')) {
			window.document.getElementById('order_all_off').style.display = "none";
			window.document.getElementById('order_all_on').style.display = "inline";
		}
	}

	return true;
}

function setAffiliatesBoxes(check_feld, do_check) 
{
	var elts = document.affiliates.elements[check_feld + '[]'];
	var elts_cnt = (typeof(elts.length) != 'undefined') ? elts.length : 0;
	if(elts_cnt) 
	{
		for(var i = 0; i < elts_cnt; i++) 
		{
			elts[i].checked = do_check;
		}
	} 
	else 
	{
		elts.checked = do_check;
	}
	if(do_check) 
	{
		if(window.document.getElementById('select_all_off')) 
		{
			window.document.getElementById('select_all_on').style.display = "none";
			window.document.getElementById('select_all_off').style.display = "inline";
		}
	} 
	else 
	{
		if (window.document.getElementById('select_all_off')) 
		{
			window.document.getElementById('select_all_off').style.display = "none";
			window.document.getElementById('select_all_on').style.display = "inline";
		}
	}

	return true;
}


function adjust_screen(direction, axe)
{
	var element = document.getElementById('cube');
	
	var int = document.getElementById('interval').value;
	
	if(is_numeric(int) === false)
	{
		alert('Bitte geben Sie eine gültige Zahl bei Interval ein!');
	}
	else
	{
		if(axe == 'x')
		{	
			if(direction == 'up')
			{
				var cur_width = parseInt(str_replace('px', '', element.style.width));
				if(cur_width+parseInt(int)<=558)
				{
					element.style.width = cur_width+parseInt(int)+'px';
					document.getElementById('adjustx').value = cur_width+parseInt(int)+2;
				}
				else
				{
					alert('Das Rechteck kann nicht weiter vergrößert werden.');
				}
			}
			else if(direction == 'down')
			{
				var cur_width = parseInt(str_replace('px', '', element.style.width));
				if(cur_width-parseInt(int)>=10)
				{
					element.style.width = cur_width-parseInt(int)+'px';
					document.getElementById('adjustx').value = cur_width-parseInt(int)+2;
				}
				else
				{
					alert('Das Rechteck kann nicht weiter verkleinert werden.');
				}
			}
		}
		else if(axe == 'y')
		{
			if(direction == 'up')
			{
				var cur_height = parseInt(str_replace('px', '', element.style.height));
				if(cur_height+parseInt(int)<=400)
				{
					element.style.height = cur_height+parseInt(int)+'px';
					document.getElementById('adjusty').value = cur_height+parseInt(int)+2;
				}
				else
				{
					alert('Das Rechteck kann nicht weiter vergrößert werden.');
				}
			}
			else if(direction == 'down')
			{
				var cur_height = parseInt(str_replace('px', '', element.style.height));
				if(cur_height-parseInt(int)>=10)
				{
					element.style.height = cur_height-parseInt(int)+'px';
					document.getElementById('adjusty').value = cur_height-parseInt(int)+2;
				}
				else
				{
					alert('Das Rechteck kann nicht weiter verkleinert werden.');
				}
			}
		}
	}
}

var open_view_element = '';
function open_view_option(id)
{
//	open_view_element = document.getElementById('select_'+id);
	Effect.toggle('select_'+id, 'slide');
}

function switch_newsletter(obj)
{
	if(obj.value==2)
	{
		document.getElementById('company').style.display = display;
		document.getElementById('salutation').style.display = display;
		document.getElementById('firstname').style.display = display;
		document.getElementById('lastname').style.display = display;
	}
	else
	{
		document.getElementById('company').style.display = 'none';
		document.getElementById('salutation').style.display = 'none';
		document.getElementById('firstname').style.display = 'none';
		document.getElementById('lastname').style.display = 'none';
	}
}