
var im1 = new Image();
im1.src = '/images/splash/header_quick_prev_hover.png';

var im2 = new Image();
im2.src = '/images/splash/header_quick_prev_hover.png';

var is_opened_combo = false;
var combo_time = false;
var is_playing_effect = false;
var header_quick_width = 0;
var product_image_tooltip_hndlr = false;
var header_quick_cache = {};
var header_quick_actual_url = false;
var pf_table = [];
var teaser_handler = false;

function getClientWidth(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function getBodyScrollTop(){
	return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft(){
	return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function getClientCenterX(){
	return parseInt(getClientWidth()/2)+getBodyScrollLeft();
}

function getClientCenterY(){
	return parseInt(getClientHeight()/2)+getBodyScrollTop();
}

function getDocumentHeight(){
	return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}

function getElementPosition(elem){
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}

function show_menu_pointer(elem){
	var left = parseInt(jQuery(elem).css('left')) + parseInt(jQuery(elem).width())/2 - 7;
	jQuery('.main_menu_pointer').css({'left':left+'px'}).show();
}

function init_quick(str){
  jQuery('.header_quick_prev').attr('src','/images/splash/header_quick_prev.png');
	jQuery('.header_quick_next').attr('src','/images/splash/header_quick_next.png');
	var count = jQuery('<div>'+str+'</div>').find('a').size();
	header_quick_width = 143*count + 12*(count-1);
	jQuery('.header_quick_elems').css({width:header_quick_width, left:0});
	
	jQuery('.header_quick_prev').click(header_quick_prev);
	jQuery('.header_quick_next').click(header_quick_next);
	var current = jQuery('.header_quick_elems a.active').index('.header_quick_elems a');
  
  
  
  //alert(current);
  if (current >= 6){
    var new_left = parseInt(jQuery('.header_quick_elems').css('left'));
	  new_left -= (143 + 12)*(current+1-6);
    is_playing_effect = true;
		jQuery('.header_quick_elems').animate({left:new_left}, 400, function(){ is_playing_effect = false; });
  }
  
	if (current >= 6) jQuery('.header_quick_prev').attr('src','/images/splash/header_quick_prev_hover_mig.gif');
	if (count>current+1 && count>6) jQuery('.header_quick_next').attr('src','/images/splash/header_quick_next_hover_mig.gif');
	
	jQuery('.header_quick_elems a.ajax_click').click(function(){
		var url = jQuery(this).attr('href');

		get_category_childs(url);
		return false;
	});
}

function header_quick_prev(){
	var left = parseInt(jQuery('.header_quick_elems').css('left'));
	var new_left = left + (143 + 12);
	if (!is_playing_effect && left<0){
		is_playing_effect = true;
		jQuery('.header_quick_elems').animate({left:new_left}, 400, function(){ is_playing_effect = false; jQuery('.header_quick_next').attr('src','/images/splash/header_quick_next_hover_mig.gif') });
	}
	
	if (new_left>=0) jQuery('.header_quick_prev').attr('src','/images/splash/header_quick_prev.png');
	
}

function header_quick_next(){
	var left = parseInt(jQuery('.header_quick_elems').css('left'));
	var new_left = left - (143 + 12);
	if (!is_playing_effect && (header_quick_width+left)>918){
		is_playing_effect = true;
		jQuery('.header_quick_elems').animate({left:new_left}, 400, function(){ is_playing_effect = false; jQuery('.header_quick_prev').attr('src','/images/splash/header_quick_prev_hover_mig.gif');});
	}
	if ((header_quick_width+new_left)<=918) jQuery('.header_quick_next').attr('src','/images/splash/header_quick_next.png');
}

function set_quicks_cache(key, value){
	header_quick_cache[key] = value;
}

function get_quicks_cache(key){
	return header_quick_cache[key]==undefined || header_quick_cache[key]==null ? '' : header_quick_cache[key];
}

function get_category_childs(url){
	var value = get_quicks_cache(url);
	if (value!=''){
		set_quicks_data(value);
		return false;
	}
	
	header_quick_actual_url = url;
	
	jQuery.post(
		'/',
		{is_ajax:1, get_category_childs:1, url:url},
		function(data){
			var obj = jQuery(data);
			set_quicks_cache(url, obj.html())
			if (obj.attr('title')==header_quick_actual_url)
				set_quicks_data(obj.html());
			return false;
		}
	);
	return false;
}

function set_quicks_data(str){
	jQuery('.header_quick_elems').html('');
	jQuery('.header_quick_elems').html(str);
	init_quick(str);
}

jQuery(document).ready(function(){
	
	init_quick(jQuery('.header_quick_elems').html());
	
	jQuery(window).bind("focus",function(event){
        if (teaser_handler)
			clearInterval(teaser_handler);
		teaser_handler = setInterval('change_teaser()', 4000);
    }).bind("blur", function(event){
        if (teaser_handler)
			clearInterval(teaser_handler);
    });
	
	jQuery('.main_menu a.ajax_click').click(function(){
		var url = jQuery(this).attr('href');
		get_category_childs(url);
		show_menu_pointer(this);
		return false;
	});
	
	jQuery('.main_menu a.active').each(function(){
		show_menu_pointer(this);
		return false;
	});
	
	jQuery('.footer_menu div').hover(
		function(){
			jQuery(this).find('>ul').css({display:'block', visibility:'visible'});
		},
		function(){
			jQuery(this).find('>ul').css({display:'none', visibility:'hiden'});
		}
	);
	
	jQuery('.footer_menu div ul li').hover(
		function(){
			jQuery(this).find('>ul').css({display:'block'});
			if (jQuery(this).find('>ul').size()>0){
				jQuery(this).find('>ul').css({left:'100%', margin:'0 0 0 1px'});
				
				var ep = getElementPosition(jQuery(this).find('>ul')[0]);
				if ( (ep.left + ep.width)> parseInt(getClientWidth()) ){
					var p = jQuery(this).parents('ul')[0];
					var l = (-1)*jQuery(p).width();
					jQuery(this).find('>ul').css({left:l, margin:'0 0 0 -1px'});
				}
			}
			jQuery(this).find('>ul').css({visibility:'visible'});
		},
		function(){
			jQuery(this).find('>ul').css({display:'none', visibility:'hiden'});
		}
	);
	
	/*jQuery('.header_quick_prev').hover(
		function(){
			this.src = '/images/splash/header_quick_prev_hover.png';
		},
		function(){
			this.src = '/images/splash/header_quick_prev.png';
		}
	);
	
	jQuery('.header_quick_next').hover(
		function(){
			this.src = '/images/splash/header_quick_next_hover.png';
		},
		function(){
			this.src = '/images/splash/header_quick_next.png';
		}
	);*/
	
	jQuery('.tizzer_tab_panel a').click(function(){
		var id = jQuery(this).attr('id').replace('teaser_tab_', '');
		if (jQuery('.tizzer_tab_panel a.active').size()>0 && jQuery('.tizzer_tab_panel a.active:first').attr('id')==jQuery(this).attr('id') )
			return false;
		jQuery('.teasers_content .active').fadeOut(200).removeClass('active');
		jQuery('#teaser_image_'+id).fadeIn(200).addClass('active');
		jQuery('.tizzer_tab_panel a').removeClass('active');
		jQuery(this).addClass('active');
		if (teaser_handler)
			clearInterval(teaser_handler);
		teaser_handler = setInterval('change_teaser()', 4000);
		return false;
	});
	
	teaser_handler = setInterval('change_teaser()', 4000);
	
	jQuery('.contact_form_combo_content li, .form_combo_content li').hover(
		function(){
			jQuery(this).css({'background':'#dfebef', 'color':'#4f89a6'});
			if (combo_time)
				clearTimeout(combo_time);
		},
		function(){
			jQuery(this).css({'background':'#ffffff', 'color':'#4f89a6'});
			combo_time = setTimeout(close_combo, 500);
		}
	);
	
	jQuery('.contact_form_combo_content li').click(function(){
		var val = jQuery(this).attr('title');
		var val_title = jQuery(this).find('span').html();
		var par =jQuery(this).parents('.contact_form_combo')[0];
		
		jQuery(par).find(':input').attr('value', val);
		jQuery(par).find('.contact_form_combo_elem span').html(val_title);
	});
	
	jQuery('.contact_form_combo_show_btn').click(function(){
		var par = this.parentNode;
		jQuery(par).find('.contact_form_combo_content').show();
		is_opened_combo = false;
		if (combo_time)
			clearTimeout(combo_time);
		combo_time = setTimeout(close_combo, 1000);
	});
	
	jQuery('.products_combo_content li').hover(
		function(){
			jQuery(this).css({'background':'#dfebef', 'color':'#4f89a6'});
			if (combo_time)
				clearTimeout(combo_time);
		},
		function(){
			jQuery(this).css({'background':'#ffffff', 'color':'#4f89a6'});
			combo_time = setTimeout(close_combo, 500);
		}
	);
	
	jQuery('.products_combo_content li').click(function(){
		var val = jQuery(this).attr('title');
		var val_title = jQuery(this).find('span').html();
		var par =jQuery(this).parents('.products_combo')[0];
		
		jQuery(par).find(':input').attr('value', val);
		jQuery(par).find('.products_combo_elem span').html(val_title);
		
		var func = $(par).attr('change');
		if (func!=null && func!=undefined){
			try{
				eval(func);
			}catch(e){
			}
		}
		close_combo();
	});
	
	jQuery('.combo_show_btn').click(function(){
		var par = this.parentNode;
		var count = jQuery(par).find('.products_combo_content li').size();
		if (count>10){
			jQuery(par).find('.products_combo_content').css({'height':'220px', 'overflow':'auto'});
		}else{
			jQuery(par).find('.products_combo_content').css({'height':'auto', 'overflow':'auto'});
		}
		jQuery(par).find('.products_combo_content').show();
		is_opened_combo = false;
		if (combo_time)
			clearTimeout(combo_time);
		combo_time = setTimeout(close_combo, 1000);
	});
	
	jQuery(document).click(function(){
		if (is_opened_combo){
			close_combo();
		}else{
			is_opened_combo = true;
		}
	});
	
	jQuery('.dp_radio').click(function(){
		var tmp = jQuery(this).attr('alt').split('__');
		var id = tmp[0];
		var value = tmp[1];
		jQuery('.dp_radio').each(function(){
			if (jQuery(this).attr('alt').indexOf(id+'__')!=-1 && (this.src.indexOf('/images/warenkorb/register/dp_radio_checked.png')!=-1 || this.src.indexOf('/images/warenkorb/register/dp_radio_a.png')!=-1))
				this.src = '/images/warenkorb/register/dp_radio.png';
		});
		this.src = '/images/warenkorb/register/dp_radio_checked.png';
		jQuery('#'+id+'_id').attr('value', value);
	});
	
	jQuery('.dp_checkbox').click(function(){
		var id = jQuery(this).attr('id');
		if (this.src.indexOf('/images/warenkorb/overview/dp_checkbox.png')!=-1){
			this.src = '/images/warenkorb/overview/dp_checkbox_checked.png';
			jQuery('#'+id+'_hidden').attr('value', '1');
		}else{
			this.src = '/images/warenkorb/overview/dp_checkbox.png';
			jQuery('#'+id+'_hidden').attr('value', '0');
		}
	});
	
	combo_init();
	
	jQuery('.product_image_tooltip').hover(
		function(){
			if (product_image_tooltip_hndlr)
				clearTimeout(product_image_tooltip_hndlr);
		},
		function(){
			hide_image_tooltip();
		}
	);
  
  jQuery('.box_info_href.show-table').click(function(){
    var el_show = jQuery(this).parent('div').find('.info-table');
    if (el_show.css('display') == 'block') el_show.slideUp('slow'); else el_show.slideDown('slow');
  });
});

function change_teaser(){
	var obj = jQuery('.tizzer_tab_panel a.active').nextAll('a:first');
	if (obj.size()!=0){
		obj.click();
	}else{
		jQuery('.tizzer_tab_panel a:first').click();
	}
}

function close_combo(){
	jQuery('.contact_form_combo_content').hide();
	jQuery('.products_combo_content').hide();
}

function combo_init(){
	$('.contact_form_combo').each(function(){
		var selected = jQuery(this).find('.contact_form_combo_content li.selected');
		if (selected.size()!=0){
			selected.click();
		}else{
			jQuery(this).find('.contact_form_combo_content li:first').click();
		}
	});
	
	$('.products_combo').each(function(){
		var selected = jQuery(this).find('.products_combo_content li.selected');
		if (selected.size()!=0){
			selected.click();
		}else{
			jQuery(this).find('.products_combo_content li:first').click();
		}
	});
}

function check_contact_form(form){
	if (form['form_data[surname]'].value=='' ||
		form['form_data[name]'].value=='' ||
		form['form_data[company]'].value=='' ||
		form['form_data[street]'].value=='' ||
		form['form_data[zip]'].value=='' ||
		form['form_data[city]'].value=='' ||
		form['form_data[phone]'].value=='' ||
		form['form_data[email]'].value=='' ||
		form['form_data[comment]'].value==''
	){
		alert('Mit einem * gekennzeichnete Felder sind Pflichtfelder. Bitte erganzen Sie Ihre Angaben.');
		return false;
	}
	return true;
}


function show_image_tooltip(elem, url){
if (product_image_tooltip_hndlr)
		clearTimeout(product_image_tooltip_hndlr);
	var cords = getElementPosition( jQuery(elem).parents('.fk_box_product')[0] );
	var top = cords.top - jQuery('.product_image_tooltip').height() - 30;
	top = $(document).scrollTop() > top ? $(document).scrollTop() : top;
	jQuery('.product_image_tooltip .product_image_tooltip_content').css({'background-image':'url(/images/index/preloader.gif)'});
	jQuery('.product_image_tooltip').css({top:top});
	var img = new Image();
	img.onload = function(){
		jQuery('.product_image_tooltip .product_image_tooltip_content').css({'background-image':'url('+this.src+')'});
	};
	img.src = url;
	jQuery('.product_image_tooltip').show();
	return false;
}

function hide_image_tooltip(){
	product_image_tooltip_hndlr = setTimeout("jQuery('.product_image_tooltip').hide();", 300);
}

function show_bitte_warten(){
	var l = getClientCenterX();
	var t = getClientCenterY();
	jQuery('.bitte_warten').css({'left':l+'px', 'top':t+'px', 'margin':'-76px 0 0 -141px'});
	jQuery('.bitte_warten').show();
}

function show_popup(id){
	var h = 0;
	jQuery('#popup_shadow').height(jQuery('.content_wrapper').height());
	if ( getClientHeight()<610 ){
		jQuery('#'+id).css('top', getBodyScrollTop()+20+'px');
	}else{
		jQuery('#'+id).css('top', getClientCenterY()+'px');
		h = parseInt(580)/2;
	}
	var w = parseInt(711)/2;
	jQuery('#'+id).css('margin', '-'+h+'px 0 0 -'+w+'px');
	
	jQuery('#popup_shadow').show();
	jQuery('#'+id).show();
	return false;
}

function hide_popup(id){
	jQuery('#'+id).hide();
	jQuery('#popup_shadow').hide();
	return false;
}

function radio_set_value(id, value){
	jQuery('.dp_radio').each(function(){
		var tmp = jQuery(this).attr('alt').split('__');
		var tid = tmp[0];
		var tvalue = tmp[1];
		if (tid==id){
			if (value==''){
				$('#'+id+'_id').val('');
			}
			if (tvalue==value)
				jQuery(this).click();
			else
				this.src = '/images/warenkorb/register/dp_radio.png';
		}
	});
}

function combo_set_value(id, value){
	var is_find = false;
	jQuery('#'+id).find('.products_combo_content li').each(function(){
		if (jQuery(this).attr('title')==value){
			jQuery(this).click();
			is_find = true;
		}
	});
	if (!is_find){
		jQuery('#'+id).find('.products_combo_content li:first').click();
	}
}
 
function change_product_color(elem, id){
	var box_id = jQuery(elem).parents('.fk_box_product')[0].id.replace('product_', '');
	
	jQuery('#product_'+box_id+' .fk_box_pr_title').html(products_info[box_id][id].name);
	jQuery('#product_'+box_id+' .fk_box_pr_price').html('ab '+'<b>'+products_info[box_id][id].price+' &euro;</b>');
	jQuery('#product_'+box_id+' .fk_box_pr_img').css('background-image', 'url('+products_info[box_id][id].img+')').attr('onmouseover', "show_image_tooltip(this, '"+products_info[box_id][id].imgBig+"');");
}

/** code for block bestellung *****************************************/
var comboHide;
var combo_ids=new Array();

document.onmousedown = function() {
	if (!comboHide) return;
	for (i=0;i<combo_ids.length;i++){
	  if (document.getElementById(combo_ids[i])) {
		  document.getElementById(combo_ids[i]).style.visibility = 'hidden';
		  document.getElementById(combo_ids[i]).style.display = 'none';
		  document.getElementById(combo_ids[i]).innerHTML='';
	  }
	}
}

function create_table(elm,items,values,parent)
{
	var mybody=document.getElementById(elm);
	var sep = false;
	mybody.innerHTML = '';
	temp = '';

	temp += '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
	for(j=0;j<items.length-1;j++)
	{
			if (elm == 'land' && j==4) sep=true;
			temp += '<tr><td val="'+values[j]+'" onmouseover="this.style.backgroundColor=\'#E5E5E5\'; this.style.color=\'#000000\'" onmouseout="this.style.backgroundColor=\'#FFFFFF\'; this.style.color=\'#000000\';" onclick="cmbx_select_item(this, \''+elm+'\');" style="padding:0px 2px 0px 3px; cursor: pointer; color:#000000;'+((sep)? 'border-bottom:1px solid #CCCCCC;' : '' )+'" nowrap>';
			temp += items[j];
			temp += '</td></tr>';
			sep = false;

	}
	temp += '</table>';
	mybody.innerHTML = temp;
}

function cmbx_select_item(thisitem,elm)
{
	document.getElementById(elm+'_parent').value = thisitem.getAttribute('val');
	if (document.getElementById(elm+'_visible').getAttribute('tp')=='input')
	  document.getElementById(elm+'_visible').value = thisitem.innerHTML.replace(/&amp;/,'&');
	else
	  document.getElementById(elm+'_visible').innerHTML = thisitem.innerHTML.replace(/&amp;/,'&');
		
	display_switch(elm,null,null,elm+'_parent');
	var onchange=document.getElementById(elm+'_parent').getAttribute('onchange_event');
    if (onchange!='') eval(onchange+'(\''+thisitem.getAttribute('val')+'\')');
}

function display_switch(element,items,values,parent)
{
	if (document.getElementById(element).style.visibility == 'hidden') {
	  width=document.getElementById(element).style.width;
	  document.getElementById(element).style.height='100px';	
	  create_table(element,items,values,parent);
	  document.getElementById(element).style.visibility =  '';
	  document.getElementById(element).style.display = 'block';
	  document.getElementById(element).style.width=width;	
	  comboHide=true;
	} else {
  	  document.getElementById(element).style.visibility =  'hidden';
	  document.getElementById(element).style.display = 'none';
  	  document.getElementById(element).innerHTML='';
  	  comboHide=false;
	}
}

function combobox_set_selected(id,items,values,def) {
	found=false;
	for (i=0;i<values.length;i++)
	 if (items[i]==def && def!='') {
		def=items[i];
		document.getElementById(id+'_parent').value=values[i];
		found=true;
		break;
	 }

	if (!found && values.length>0) {
		def=items[0];
		document.getElementById(id+'_parent').value=values[0];
	}
	//temp = document.createElement("FONT");
	//temp.innerHTML = def;

	if (document.getElementById(id+'_visible').getAttribute('tp')=='input')
		  document.getElementById(id+'_visible').value = def;
		else
		  document.getElementById(id+'_visible').innerHTML = def;
	
	
	//document.getElementById(id+'_visible').value=temp.innerHTML;
	var onchange=document.getElementById(id+'_parent').getAttribute('onchange_event');
    if (onchange!='') eval(onchange+'(\''+document.getElementById(id+'_parent').value+'\')');
}

function ch_material(val) {
	
	pf_table = [];
	var tmp = [];
	
	var code='<table border="0" cellspacing="0" cellpadding="0" class="fb_best_table">';
	
	for(var i=0;i<posters.length;i++){
		if (posters[i][0]==val){
			tmp = [posters[i][2], posters[i][5], posters[i][4], posters[i][6], posters[i][1]];
			pf_table.push(tmp);
			if (posters[i][3]=='radio')
				code+='<tr><td class="fb_best_table_radio"><input type="radio" name="format" value="'+posters[i][1]+'"></td><td class="fb_best_table_text">'+posters[i][2]+'</td><td class="fb_best_table_cena">'+posters[i][4]+' &euro;</td></tr>';
		}
	}
	
	code+='</table>';
	document.getElementById('buyblock').innerHTML=code;
}

function ch_format(val) {
	if (val!='') document.getElementById('format_from_combobox').checked=true;
}

function buyblock_submit(checksubmit) {
/*
	if (document.getElementById('realupload').value=='') {
		alert('Please select image');
		return;
	}
*/
	// check format
	var els=document.getElementById('uu_upload').getElementsByTagName('INPUT');
	var format='';
	for(var i=0;i<els.length;i++)
		if (els[i].name=='format' && els[i].checked) format=els[i].value;
	if (format=='from_combobox') { format=document.getElementById('formatuniq_parent').value; }
	if (format=='') {
		alert('Select please format');
		return false;
	}
	
	var npos=format.indexOf(",");
	if (npos>0) {
		var pt_id=format.substr(0,npos);
		var p_shortname=format.substr(npos+1,format.length-npos);
		document.getElementById('pt_id').value=pt_id;
		document.getElementById('p_shortname').value=p_shortname;
		if (!checksubmit) document.getElementById('uu_upload').submit();
		return true;
	}
	
	return false;
	// linkUpload();
}



// Shop product comboboxes

function showPopupTable(element){
	number=element.replace('fps_', '');
	
	if (parents[number]!='' && document.getElementById('fps_'+parents[number]+'_parent').value=='')
		return;
	
	if (document.getElementById(element).style.visibility == 'hidden') {
	  width=document.getElementById(element).style.width;
	  document.getElementById(element).style.height='';	
	  fps_create_table(element);
	  document.getElementById(element).style.visibility = '';
	  document.getElementById(element).style.display = 'block';
	  document.getElementById(element).style.width=width;	
	  comboHide=true;
	} else {
  	  document.getElementById(element).style.visibility = 'hidden';
	  document.getElementById(element).style.display = 'none';
  	  document.getElementById(element).innerHTML='';
  	  comboHide=false;
	}
}

function fps_create_table(elm){
	var mybody=document.getElementById(elm);
	var sep = false;
	mybody.innerHTML = '';
	temp = '';
	number=elm.replace('fps_', '');
	nf=-1;
	tmp_rows=[];
	tmp_arr=[];
	
	for (i=0; i<fields.length; i++)
		if (number==fields[i]){
			nf=i;
			break;
		}
		
	for(j=0;j<fps_items.length;j++){
		is_ok=true;
		for (i=0; i<nf; i++){
			if (document.getElementById('fps_'+fields[i]+'_parent').value!=fps_items[j][i][1]){
				is_ok=false;
				break;
			}
		}
		if (is_ok){
			is_uniq=true;
			for (k=0; k<tmp_arr.length; k++)
				if (tmp_arr[k]==fps_items[j][nf][1]){
					is_uniq=false;
					break;
				}
			if (is_uniq){
				tmp_rows.push(new Array(fps_items[j][nf][0], fps_items[j][nf][1]));
				tmp_arr.push(fps_items[j][nf][1]);
			}
		}
	}
	tmp_rows.sort(cmp);

	temp += '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
	for(j=0;j<tmp_rows.length;j++)
	{
			if (elm == 'land' && j==4) sep=true;
			temp += '<tr><td val="'+tmp_rows[j][1]+'" onmouseover="this.style.backgroundColor=\'#E5E5E5\'; this.style.color=\'#000000\'" onmouseout="this.style.backgroundColor=\'#FFFFFF\'; this.style.color=\'#000000\';" onclick="cmbx_select(this, \''+elm+'\');" style="padding:0px 2px 0px 3px; cursor: pointer; color:#000000;'+((sep)? 'border-bottom:1px solid #CCCCCC;' : '' )+'" nowrap>';
			temp += tmp_rows[j][0];
			temp += '</td></tr>';
			sep = false;

	}
	temp += '</table>';
	mybody.innerHTML = temp;
}

function cmp(el1, el2){
	el1=el1[0];
	el2=el2[0];
	m1=el1.match(/^(\d+)/);
	m2=el2.match(/^(\d+)/);
	
	if (m1 && m2){
		el1=m1[0]*1;
		el2=m2[0]*1;
	}
	
	if (el1>el2)
		return 1;
	else if (el1<el2)
		return -1;
	else
		return 0;
}

function cmbx_select(thisitem,elm)
{
	if (document.getElementById(elm+'_parent').value!=thisitem.getAttribute('val'))
		reload=true;
	else
		reload=false;
	document.getElementById(elm+'_parent').value = thisitem.getAttribute('val');
	if (document.getElementById(elm+'_visible').getAttribute('tp')=='input')
	  document.getElementById(elm+'_visible').value = thisitem.innerHTML.replace(/&amp;/,'&');
	else
	  document.getElementById(elm+'_visible').innerHTML = thisitem.innerHTML.replace(/&amp;/,'&');
	if (reload)
	for (i=nf+1; i<fields.length; i++){
		document.getElementById('fps_'+fields[i]+'_parent').value="";
		if (document.getElementById('fps_'+fields[i]+'_visible').getAttribute('tp')=='input')
			document.getElementById('fps_'+fields[i]+'_visible').value = "";
		else
			document.getElementById('fps_'+fields[i]+'_visible').innerHTML = "";
	}
	showPopupTable(elm);
	changePrice();
}

function changePrice(){
	countProducts=0;
	indexProduct=-1;
	for (i=0; i<fps_items.length; i++){
		tmp=true;
		for (j=0; j<fields.length; j++)
			if (document.getElementById('fps_'+fields[j]+'_parent').value!=fps_items[i][j][1]){
				tmp=false;
				break;
			}
		if (tmp){
			indexProduct=i;
			countProducts++;
		}
	}
	if (countProducts==1)
		document.getElementById('shop_product_price').innerHTML=fps_items[indexProduct][fields.length+1]+' &euro;';
}

function checkFpsForm(elem, mainProductId){
	if (fields.length>0){
		is_ok=true;
		for (i=0; i<fields.length; i++)
			if (document.getElementById('fps_'+fields[i]+'_parent').value==''){
				is_ok=false;
				break;
			}
		if (!is_ok){
			alert('Select product parametrs');
			return false;
		}
		for (i=0; i<fps_items.length; i++){
			tmp=true;
			for (j=0; j<fields.length; j++)
				if (document.getElementById('fps_'+fields[j]+'_parent').value!=fps_items[i][j][1]){
					tmp=false;
					break;
				}
			if (tmp){
				erpid=fps_items[i][fields.length];
				break;
			}
		}
	}else
		erpid=mainProductId;
	tmp=erpid.split(',');
	elem.pt_id.value=tmp[0]-1;
	elem.p_shortname.value=tmp[1];
	return true;
}

function init_main_product(){
	for (j=0; j<main_product.length; j++){
		document.getElementById('fps_'+main_product[j][0]+'_parent').value=main_product[j][1];
		if (document.getElementById('fps_'+main_product[j][0]+'_visible').getAttribute('tp')=='input')
			document.getElementById('fps_'+main_product[j][0]+'_visible').value = main_product[j][2].replace(/&amp;/,'&');
		else
			document.getElementById('fps_'+main_product[j][0]+'_visible').innerHTML = main_product[j][2].replace(/&amp;/,'&');
	}
}

function fotog_visual_prev(){
	if (!is_slide_list){
		var count = $('#fotog_visual_list .fotog_visual_element').size();
		$('#fotog_visual_list').width(count*962);
		
		var l = parseInt( $('#fotog_visual_list').css('left') );
		if (l<0){
			is_slide_list = true;
			var nl = l+962;
			$('#fotog_visual_list').animate({left: nl+'px'}, 500, finish_slide);
		}
	}
}

function fotog_visual_next(){
	if (!is_slide_list){
		var count = $('#fotog_visual_list .fotog_visual_element').size();
		$('#fotog_visual_list').width(count*962);
		
		var l = parseInt( $('#fotog_visual_list').css('left') );
		var absl = Math.abs(l);
		var w = parseInt( $('#fotog_visual_list').width() );
		if ((w-absl-962)>0){
			is_slide_list = true;
			var nl = l-962;
			$('#fotog_visual_list').animate({left: nl+'px'}, 500, finish_slide);
		}
	}
}

function init_fotog_quickfinders(){
	$('.fotog_quick_link').hover(
		function(){
			var parent = this.parentNode;
			if ($(parent).hasClass('fotog_quickfinder_back'))
				parent.className += '_hover';
		},
		function(){
			var parent = this.parentNode;
			if ($(parent).hasClass('fotog_quickfinder_back_hover'))
				parent.className = parent.className.replace('_hover', '');
		}
	);
}

function init_fotog_inside_quickfinders(){
	$('.fotog_inside_quick_link').hover(
		function(){
			var parent = this.parentNode;
			if ($(parent).hasClass('fotog_inside_quickfinder_back'))
				parent.className += '_hover';
		},
		function(){
			var parent = this.parentNode;
			if ($(parent).hasClass('fotog_inside_quickfinder_back_hover'))
				parent.className = parent.className.replace('_hover', '');
		}
	);
}

function fotog_detail_thumb_prev(){
	if (!is_slide_list){
		var l = parseInt( $('.fotog_detail_thumbs_list').css('left') );
		if (l<0){
			is_slide_list = true;
			var nl = l+91;
			$('.fotog_detail_thumbs_list').animate({left: nl+'px'}, 400, finish_slide);
		}
	}
}

function fotog_detail_thumb_next(){
	if (!is_slide_list){
		var l = parseInt( $('.fotog_detail_thumbs_list').css('left') );
		var absl = Math.abs(l);
		var w = parseInt( $('.fotog_detail_thumbs_list').width() );
		if ((w-absl-3*91)>90){
			is_slide_list = true;
			var nl = l-91;
			$('.fotog_detail_thumbs_list').animate({left: nl+'px'}, 400, finish_slide);
		}
	}
}

function thumb_click(index){
	if (images[index]!=undefined){
		$('.fotog_detail_image').css('background-image', '');
	}
}

function finish_slide(){
	is_slide_list = false;
}

function getDocumentHeight(){
	return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}

function getClientHeight(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function getBodyScrollTop(){
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getClientCenterY(){
	return parseInt(getClientHeight()/2)+getBodyScrollTop();
}


function fotog_detail_zoom(){
	var erpid = $('#fotog_erpid').val();
	var i;
	var url = '';
	for (i=0; i<products_list.length; i++){
		if (products_list[i][0]==erpid){
			url = products_list[i][3];
			break;
		}
	}
	if (url=='')
		return;
	$('#fotog_popup_wrapper').height(getDocumentHeight());
	if ( getClientHeight()<320 ){
		$('#fotog_back_big_image').css('top', getBodyScrollTop()+20+'px');
	}else{
		$('#fotog_back_big_image').css('top', getClientCenterY()+'px');
	}
	$('#fotog_back_big_image').width(300).height(300).css('background', '#ffffff url(/images/fotogeschenke/loading.gif) center center no-repeat').css('margin', '-150px 0 0 -150px');
	$('#fotog_popup_content').html('');
	$('#fotog_popup_close').hide();
	$('#fotog_popup_wrapper').show();
	var im1 = new Image();
	im1.onload = function(){
		$('#fotog_back_big_image').css('background', '#ffffff');
		$('#fotog_back_big_image').animate({width: im1.width+40, marginLeft: -(im1.width+40)/2}, 400)
		.animate({height: im1.height+40, marginTop: -(im1.height+40)/2}, 400, function(){ $('#fotog_popup_content').html('<img src="'+url+'" alt="">'); $('#fotog_popup_close').show(); });
	}
	im1.src = url;
}

function fotog_popup_hide(){
	$('#fotog_popup_wrapper').hide();
}

function fotog_form_change(){
	$('#fotog_filter_form').submit();
}

function fotog_combobox_set_selected(id,items,values,def) {
	found=false;
	for (i=0;i<values.length;i++)
	if (values[i]==def && def!='') {
		def=items[i];
		document.getElementById(id+'_parent').value=values[i];
		found=true;
		break;
	}
	
	if (!found)
		return;
	 
	if (document.getElementById(id+'_visible').getAttribute('tp')=='input')
		document.getElementById(id+'_visible').value = def;
	else
		document.getElementById(id+'_visible').innerHTML = def;
}

function fotog_change_product(erpid){
	var i = 0;
	var j = 0;
	var obj;
	for (i=0; i<products_list.length; i++){
		if (products_list[i][0]==erpid){
			for (j=0; j<arr_selected_params.length; j++){
				$('#block_'+arr_selected_params[j]).val( products_list[i][4][arr_selected_params[j]][1] );
				fotog_select_combo(arr_selected_params[j]);
			}
			return;
		}
	}
}

function fotog_buy_product(){
	var find = true;
	var erpid = '';
	for (i=0; i<products_list.length; i++){
		find = true;
		for (j=0; j<arr_selected_params.length; j++){
			if (products_list[i][4][arr_selected_params[j]][1] != $('#block_'+arr_selected_params[j]).val()){
				find = false;
				break;
			}
		}
		if (find){
			erpid = products_list[i][0];
		}
	}
	if (erpid!=''){
		$('#erpid_number').val(erpid);
		$('#fotog_tool_form').submit();
	}else{
		alert('Wrong erpid');
	}
}

function fotog_select_combo(id){
	if (id==undefined)
		return;
	var i = 0;
	var index = -1;
	for (i=0; i<arr_selected_params.length; i++){
		if (arr_selected_params[i]==id){
			index = i;
			break;
		}
	}
	if (index==-1)
		return;
	
	if (index==(arr_selected_params.length-1)){
		fotog_product_select();
		return;
	}
	
	for (i=index+1; i<arr_selected_params.length; i++){
		$('#block_'+arr_selected_params[i]).val('');
		$('#block_'+arr_selected_params[i])[0].disabled=true;
	}
	var comb;
	comb = $('#block_'+arr_selected_params[index+1])[0];
	while (comb.options.length>1){
		comb.options[comb.options.length-1] = null;
	}
	if ($('#block_'+id).val()!=''){
		var find = true;
		var list = [];
		for (i=0; i<products_list.length; i++){
			find = true;
			for (j=0; j<=index; j++){
				if (products_list[i][4][arr_selected_params[j]][1] != $('#block_'+arr_selected_params[j]).val()){
					find = false;
					break;
				}
			}
			if (find){
				list.push([ products_list[i][4][arr_selected_params[j]][0], products_list[i][4][arr_selected_params[j]][1] ]);
			}
		}
		for (i=0; i<list.length; i++){
			comb.options[comb.options.length] = new Option(list[i][0], list[i][1]);
		}
		comb.disabled = false;
	}
}

function fotog_product_select(){
	var find = true;
	for (i=0; i<products_list.length; i++){
		find = true;
		for (j=0; j<arr_selected_params.length; j++){
			if (products_list[i][4][arr_selected_params[j]][1] != $('#block_'+arr_selected_params[j]).val()){
				find = false;
				break;
			}
		}
		if (find){
			$('#fotog_product_price').html(products_list[i][1]+'<span>&euro;</span>');
			$('#fotog_detail_image').css('background', 'url('+products_list[i][2]+') left top no-repeat');
			$('#fotog_erpid').val(products_list[i][0]);
		}
	}
}
//**********************************
