var width = '';
var height = '';

var display = document.all ? 'inline' : 'table-row';

function switch_rightcol()
{
	var col = 'rightcol';
	if(switch_rightcol.arguments[0])
	{
		col = switch_rightcol.arguments[0];
	}
	
	var checkelem = document.getElementById('rightstat');
	var element = document.getElementById('rightcol');
	var template = document.getElementById('template').value;
	
	if(saved=='')
	{
		saved = document.getElementById('innercol').innerHTML; //+'<div class="rightFoot" id="RightFooter"><table class="rightNavBottom" border="0" cellpadding="0" cellspacing="0" style="width:170px; table-layout:fixed"><tr><td class="navi-l">&nbsp;</td></tr><tr><td class="rightfooter">&nbsp;</td></table></div>';	
	}
	
	if(checkelem.value == 0)
	{
		//saved = element.innerHTML;
		element.style.width = 12+'px';
		element.textAlign = 'left';
		element.style.marginRight = '168px';
		element.innerHTML = '<span onclick="switch_rightcol(\''+col+'\')" style="cursor:pointer"><img height="40" width="10" border="0" alt="" src="/img/templates/'+template+'rc_arrows.gif"/></span>';
		checkelem.value = 1;
		document.getElementById('rightcol').style.height = 'auto';
	}
	else
	{
		element.style.width = 170+'px';
		element.style.marginRight = '0px';
		element.innerHTML = saved;
		checkelem.value = 0;
		TableContenResize();
	}
	
	
	gonext('invisiblechange', "/xmlhttp/"+col+"?stat="+checkelem.value);
}

function client_info()
{
	if(typeof $j != 'undefined'){
		$j('#MenuOpener').click(function(){
			$j('#MenuBar').slideToggle(function(){
				$j.get('/xmlhttp/settoolbar');
			});
		});
	}
	
	
	if(document.getElementById('rightstat'))
	{
		if(document.getElementById('rightstat').value == '0')
		{
			TableContenResize();
		}
	}
	
	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();
	popUpPictures('innercontent');
	popUpPictures('innercol', 'right');
	if(document.getElementById('rightColSpacer')){
		document.getElementById('rightColSpacer').style.height = document.getElementById('Header').offsetHeight-28+'px';
	}
}

function showAGB()
{
	window_open('/texts/agb', '600', '700');
}

function showPolicy()
{
	window_open('/texts/privacypolicy', '600', '700');
}

var open_popup = '';
function window_open(url)
{
	if(window_open.arguments[4]){
		open_popup = '';
	}
	
	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;
}

function MySelfCheck(){
	if(open_popup!='')
	{
		open_popup.close();	
		open_popup = '';
	}
};

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);
	}
	if(document.getElementById('mouse_cursor')){
		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();*/
	document.getElementById(what).submit();
}

function check_switch_ajax(obj, what)
{
	$j('#ProductViews').html('<center><img src="/img/wait.gif" alt="" title="" /></center>');
	new Request({ 	method: 'post',
					url:'/admin/statistics/productviewsinner',
					onComplete: function(data) { $j('#ProductViews').html(data);}
				      }).send('show='+obj.value);
	document.location.href = '#top';
}

function paginateAjax(page){
	$j('#ProductViews').html('<center><img src="/img/wait.gif" alt="" title="" /></center>');
	new Request({ 	method: 'post',
					url:'/admin/statistics/productviewsinner',
					onComplete: function(data) { $j('#ProductViews').html(data);}
				      }).send('page='+page);
	document.location.href = '#top';
	
}

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';
	}
}

function toggle_menu(sid)
{
	if(document.getElementById('sub_point_'+sid))
	{
		if(document.getElementById('sub_point_'+sid).style.display == 'none')
		{
			document.getElementById('sub_point_'+sid).style.display = display;
		}
		else
		{
			document.getElementById('sub_point_'+sid).style.display = 'none';
		}
	}
}

function popUpPictures(area_id)
{
	if(popUpPictures.arguments[1])
	{
		var index = popUpPictures.arguments[1]+'_';
	}
	else
	{
		var index = '';
	}
	
	if(area_id && document.getElementById(area_id))
	{
		var area = document.getElementById(area_id);
		var el = area.getElementsByTagName('IMG');
		
		for(var i = 0; i<el.length; i++)
		{
			var bname = basename(el[i].src);
			if(document.getElementById('pop_'+index+bname))
			{
				var src = document.getElementById('pop_'+index+bname).value;
				var popwidth = document.getElementById('pop_'+index+bname+'_width').value;
				var popheight = document.getElementById('pop_'+index+bname+'_height').value;
				el[i].style.cursor = 'pointer';
				//el[i].setAttribute('onclick', 'PICextend(\''+src+'\', \''+popwidth+'\', \''+popheight+'\');');
				if(document.all){
					el[i].onclick = function(){PICextend(src, popwidth, popheight);};
					el[i].title = document.getElementById('label_popup').value;
				} else {
					el[i].setAttribute('onclick',  'PICextend(\''+src+'\', \''+popwidth+'\', \''+popheight+'\');');
					el[i].setAttribute('title', document.getElementById('label_popup').value);
				}
			}
		}
	}
}

function basename(path, suffix) {
    var b = path.replace(/^.*[\/\\]/g, '');
        if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b.toLowerCase();
}

function TableContenResize()
{
	if (document.getElementById('rightcol') && document.getElementById('MainFrame')) {
		var rightbox = document.getElementById('rightcol');
		var leftbox = document.getElementById('MainFrame');
		
		if (rightbox.offsetHeight > leftbox.offsetHeight) {
			leftbox.style.minHeight = (rightbox.offsetHeight-2)+'px';
			if(document.getElementById('MainFooterTable') && document.getElementById('MainMainTable'))
			{
				///alert((rightbox.offsetHeight-document.getElementById('MainMainTable').offsetHeight-6));
				if(document.all)
				{
					document.getElementById('RightFooter').style.height = (document.getElementById('Footer').offsetHeight+20)+'px';
					document.getElementById('Content').style.height = (document.getElementById('RightColContent').offsetHeight-18)+'px'; //(rightbox.offsetHeight-document.getElementById('MainFooterTable').offsetHeight-126)+'px';
				}
				else
				{
					document.getElementById('Content').style.height = document.getElementById('RightColContent').offsetHeight+'px'; //(rightbox.offsetHeight-document.getElementById('MainFooterTable').offsetHeight-126)+'px';
				}
			}
		}
		else if (rightbox.offsetHeight < leftbox.offsetHeight) {
			rightbox.style.height = (leftbox.offsetHeight-2)+'px';
			if(document.getElementById('RightColContent') && document.getElementById('RightFooter')){
				if(document.all)
				{
					document.getElementById('RightColContent').style.height = (document.getElementById('Content').offsetHeight-52)+'px';
					document.getElementById('RightFooter').style.height = (document.getElementById('Footer').offsetHeight+19)+'px';
				}
				else
				{
					document.getElementById('RightColContent').style.position = 'relative';
					document.getElementById('RightColContent').style.height = document.getElementById('Content').offsetHeight+'px';
				}
			}
		}
		
	}
}

function createLayer()
{
	if(!document.getElementById('Layer')){
		var div = document.createElement('DIV');
		div.setAttribute('id', 'Layer');
		div.style.position = 'absolute';
		div.style.width = '100%';
		div.style.height = '100%';
		div.style.top = '0px';
		div.style.left = '0px';
		div.style.zIndex = 99;
		
		if(createLayer.arguments[0]){
			div.style.filter = 'alpha(opacity=60)';
			div.style.background = '#999999';
			div.style.mozOpacity = '0.6'; 
			div.style.opacity = '0.6';
		}else{
			div.style.cursor = 'wait';
		}
		
		document.body.appendChild(div);
	}
}

function removeLayer(){
	if(document.getElementById('Layer')){
		document.body.removeChild(document.getElementById('Layer'));
	}
}

function CheckReview(obj){
	if(obj.checked === true){
		if(document.all){
			var elem = document.getElementById('iePublisher').innerHTML;
			elem = elem.replace(' disabled="disabled"', '');
			elem = elem.replace(' disabled', '');
			document.getElementById('iePublisher').innerHTML = elem;
		}else{
			document.getElementById('publisher').disabled = false;
		}	
	}else{
		if(document.all){
			var elem = document.getElementById('iePublisher').innerHTML;
			elem = elem.replace('>', ' disabled="disabled">');
			document.getElementById('iePublisher').innerHTML = elem;
		}else{
			document.getElementById('publisher').disabled = true;
		}
	}
}

function checkAttributes(){
	if(document.getElementById('colorSelect')){
		var att = 'color';
	}else if(document.getElementById('sizeSelect')){
		var att = 'size';
	}
	
	if(att){
		var select = document.getElementById(att+'Select');
		for(var i = 0; i < select.options.length; i++){
			if(select.options[i].selected === true){
				//alert(select.options[i].value);
				if(document.getElementById('size_'+select.options[i].value+'_Select')){
					if(document.getElementById('size_'+select.options[i].value+'_Select').options.length==1){
						//calcAttribute();
					}
					document.getElementById('size_'+select.options[i].value+'_Select').style.display = display;
					document.getElementById('label').style.display = display;
				}else if(document.getElementById('color_'+select.options[i].value+'_Select')){
					if(document.getElementById('color_'+select.options[i].value+'_Select').options.length==1){
						//calcAttribute();
					}
					document.getElementById('color_'+select.options[i].value+'_Select').style.display = display;
					document.getElementById('label').style.display = display;
				}else{
					document.getElementById('label').style.display = 'none';
				}
			}else{
				if(document.getElementById('size_'+select.options[i].value+'_Select')){
					document.getElementById('size_'+select.options[i].value+'_Select').style.display = 'none';
					//calcAttribute();
				}
			}
		}
	}
	if(!checkAttributes.arguments[0]){
		calcAttribute();
	}
}

function calcAttribute(){
	if(document.getElementById('colorSelect')){
		var att = 'color';
	}else if(document.getElementById('sizeSelect')){
		var att = 'size';
	}
	
	if(att){
		var value = null;
		var select = document.getElementById(att+'Select');
		for(var i = 0; i < select.options.length; i++){
			if(select.options[i].selected === true){
				value = select.options[i].value;
				
				if(document.getElementById('size_'+select.options[i].value+'_Select')){
					var subselect = document.getElementById('size_'+select.options[i].value+'_Select');
					for(var y = 0; y < subselect.options.length; y++){
						if(subselect.options[y].selected === true){
							value = subselect.options[y].value;
						}
					}
				}
				if(document.getElementById('color_'+select.options[i].value+'_Select')){
					var subselect = document.getElementById('color_'+select.options[i].value+'_Select');
					for(var y = 0; y < subselect.options.length; y++){
						if(subselect.options[y].selected === true){
							value = subselect.options[y].value;
						}
					}
				}
			}
		}
		
		//alert(value);
		if(value){
			createLayer();
			var url = document.location.href;
			if(stripos(url, '&subdetail')){
				url = url.substring(0, stripos(url, '&subdetail'));
			}
			url = url+'&subdetail='+value;
			document.location.href = url;
		}
	}
}

function showHelp(obj)
{
	var txt = obj.getAttribute('txt');
	if(txt) {
		var helppopup = document.createElement('span');
		helppopup.className = 'helppopup';
		helppopup.id = 'helppopup';
		var helptext = document.createElement('span');
		helptext.innerHTML = txt;
		helppopup.appendChild(helptext);
		obj.parentNode.appendChild(helppopup);
	}
}

function hideHelp(obj)
{
	var helppopup = document.getElementById('helppopup');
	obj.parentNode.removeChild(helppopup);
}

function initToolbar(){
	$j('a.project').each(function(i){
		var mainObj = this;
		var target = $j(mainObj).attr('target');
		var href = $j(mainObj).attr('href');
		if(target && target=='_blank'){
			$j(mainObj).bind('click', function(){	
				$j.get('/xmlhttp/slogin', function(data){
					window.open($j(mainObj).attr('href')+data, '_blank');
				});
				return false;
			});
		}
	});
}

function setNewsLetter(obj, pro){
	if(setNewsLetter.arguments[2]){
		pro += '&u='+setNewsLetter.arguments[2];
	}
	$j.get('/xmlhttp/setnewsletter?pro='+pro, function (data){
		if(data=='1'){
			$j('input', 'a.none').each(function(i){
				if($j(this).attr('name')==$j(obj).attr('name')){
					$j(this).attr('checked', true);
				}
			});
		}else{
			$j('input', 'a.none').each(function(i){
				if($j(this).attr('name')==$j(obj).attr('name')){
					$j(this).attr('checked', false);
				}
			});
		}
	});
}
