var is_slide_list = false;


function getrandom() {
    var min_random = 0;
    var max_random = 100;
    max_random++;
    var range = max_random - min_random;
    var n=Math.floor(Math.random()*range) + min_random;
    return n;
}

var neg = getrandom(); 

function randimage(){
if (neg > 50){
	var wl = document.getElementById('splviz');
	wl.style.backgroundImage = 'url(/images/splash/vis_tr.jpg)';	
	}
}

//***************************
function fixPNG(element)
{
//Если браузер IE версии 5.5-6
if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
{
var src;

if (element.tagName=='IMG') //Если текущий элемент картинка (тэг IMG)
{
if (/\.png$/.test(element.src)) //Если файл картинки имеет расширение PNG
{
element.width = element.clientWidth;
element.height = element.clientHeight;
src = element.src;
element.src = "clear.gif"; //заменяем изображение прозрачным gif-ом
}
}
else //иначе, если это не картинка а другой элемент
{
//если у элемента задана фоновая картинка, то присваеваем значение свойства background-шmage переменной src
src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
if (src)
{
element.width = element.clientWidth;
element.height = element.clientHeight;

src = src[1]; //берем из значения свойства background-шmage только адрес картинки
element.runtimeStyle.backgroundImage="none"; //убираем фоновое изображение
}
}
//если, src не пуст, то нужно загрузить изображение с помощью фильтра AlphaImageLoader
if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='crop')";
}
}



var popUpWin=0;


function sh_popup(URLStr,widthw,heightw)
{
  var width=(widthw>0) ? widthw:380;
  var height=(heightw>0) ? heightw:470;
  var left = parseInt((screen.availWidth/2) - (width/2));
  var top = parseInt((screen.availHeight/2) - (height/2));

  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr+'?popup', 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

 
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

var preloadFlag = false;

function preloadImagesSplash() {
		menu1_over = newImage("/images/splash/quik_spla.jpg");
		menu2_over = newImage("/images/splash/quik_splb.jpg");
		menu3_over = newImage("/images/splash/quik_splc.jpg");
		
		menu4_over = newImage("/images/splash/m_auft.jpg");
		menu5_over = newImage("/images/splash/m_des.jpg");
		menu6_over = newImage("/images/splash/m_prod.jpg");
		menu5_over = newImage("/images/splash/m_soft.jpg");
		menu6_over = newImage("/images/splash/m_tips.jpg");	
}


function preloadImagesIndex() {
		menu1_over = newImage("/images/index/quik_ina.jpg");
		menu2_over = newImage("/images/index/quik_inb.jpg");
		menu3_over = newImage("/images/index/quik_inc.jpg");
		
		menu4_over = newImage("/images/splash/m_auft.jpg");
		menu5_over = newImage("/images/splash/m_des.jpg");
		menu6_over = newImage("/images/splash/m_prod.jpg");
		menu5_over = newImage("/images/splash/m_soft.jpg");
		menu6_over = newImage("/images/splash/m_tips.jpg");	
}


function setHeight(){
var a1 = document.getElementById('textureFixBody').clientHeight;
var b1 = a1 % 16;
	if (b1!=0) a1=a1-b1+16;
	document.getElementById('textureFixBody').height=a1;


document.getElementById('textureFixContent').style.height=document.getElementById('2xInfoboxFix').clientHeight+'px';
var a2 = document.getElementById('textureFixContent').clientHeight;
var b2 = a2 % 96;
	if (b2!=0) a2=a2-b2+96;
	document.getElementById('textureFixContent').style.height=a2+'px';
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var timer;

function urlImage(imageURL) {
	//imageURL=location.protocol+'//'+location.host+imageURL;
	
	var f="";
	f+=",scrollbars=yes,resizable=yes";
	imgWin=window.open(imageURL,'',f);
}

function popFlash(src,fwidth,fheight,ftitle) {
	src=location.protocol+'//'+location.host+src;
	var defWidth=(fwidth/1.0)+30;
	var defHeight=(fheight/1.0)+20;
	var f="width="+defWidth+",height="+defHeight;	
	f+=",left="+((screen.availWidth-defWidth)/2)+",scrollbars=yes,resizable=yes,top="+((screen.availHeight-defHeight)/2);
	flashWin=window.open('about:blank','',f);
	flDoc=flashWin.document;
	with (flDoc) {
		writeln('<html><head><title>'+ftitle+'</title><style>body{margin:0px;padding: 0;}</style><body>');
		writeln('<table border="0" width="100%" height="100%"><tr><td align="center" valign="middle">');
		writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+fwidth+'" height="'+fheight+'">');
		writeln('<param name=movie value="'+src+'"><param name=quality value=high>');
		writeln('<embed src="'+src+'" quality="high"  width="'+fwidth+'" height="'+fheight+'">'); 
		writeln('</embed></object></td></tr></table></body></html>');
		close();
	}
}

function popImage(imageURL,imgTitle) {
	imageURL=location.protocol+'//'+location.host+imageURL;
	var defWidth=0.75*screen.availWidth;
	var defHeight=0.75*screen.availHeight;
	var defWidth1=10;
	var defHeight1=10;
	var f="width="+defWidth1+",height="+defHeight1;	
	f+=",left="+((screen.availWidth-defWidth)/2)+",scrollbars=yes,resizable=yes,top="+((screen.availHeight-defHeight)/2);
	imgWin=window.open('about:blank','',f);
	imDoc=imgWin.document;
	with (imDoc) {
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
		writeln('width=100-(document.body.clientWidth-document.images[0].width);if (width>0.75*screen.availWidth) width=0.75*screen.availWidth;');
		writeln('height=100-(document.body.clientHeight-document.images[0].height);if (height>0.75*screen.availHeight) height=0.75*screen.availHeight;');
		writeln('window.resizeTo(width,height);}');writeln('else {');       
		writeln('window.innerWidth=document.images["George"].width<0.75*screen.availWidth ? document.images["George"].width:0.75*screen.availWidth;');
		writeln('window.innerHeight=document.images["George"].height<0.75*screen.availHeight ? document.images["George"].height:0.75*screen.availHeight;}}');
		writeln('function doTitle(){document.title="'+imgTitle+'";}');writeln('</sc'+'ript>');
		writeln('</head><body bgcolor="#FFFFFF" onload="reSizeToImage();doTitle();self.focus()">')
		writeln('<img name="George" src="'+imageURL+'" style="display:block"></body></html>');
		
		close();
	}
}


function sitemap_open(img, id){
	if (document.getElementById(id).style['display']=='block'){
		document.getElementById(id).style['display']='none';
		img.src='/images/plus.gif';
	}
	else{		
		document.getElementById(id).style['display']='block';
		img.src='/images/minus.gif';
	}	
}


function splash_content(){		
if (neg < 50){
			  var wl = document.getElementById('wilk_image');
			  wl.width=0;
}
}
///**********************************************************
function hmenuhover()
{
 if(!document.getElementById("hmenu"))
 return;
 var lis = document.getElementById("hmenu").getElementsByTagName("LI");
 for (var i=0;i<lis.length;i++)
 {
 lis[i].onmouseover=function(){this.className+=" iehover";}
 lis[i].onmouseout=function() {this.className=this.className.replace(new RegExp(" iehover\\b"), "");}
 }
}
if (window.attachEvent)
 window.attachEvent("onload", hmenuhover);








/** 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]);
		}
	}
}