function showPopup (page,width,height,resizeable,scrollbars) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('"+page+"', '" + id + "', 'toolbar=0,scrollbars='+scrollbars+',location=0,statusbar=0,menubar=0,resizable='+resizeable+',width="+width+",height="+height+"');");
}



function showMaterialImg (dir, idx, ext, width, height) {
	var img = document.getElementById ('material_img');
	// var a = document.getElementById ('material_img_link');
	if (img) {
		if (ext)
			img.src = '/userfiles/image/'+dir+'prev2_'+idx+'.'+ext;
		else
			img.src = '/userfiles/image/'+dir+'prev2_'+idx+'.jpg';
		if (width)
			img.width = width;
		if (height)
			img.height = height;
		/*
		if (ext)
			a.href='/userfiles/image/'+dir+idx+'.'+ext;
		else
			a.href='/userfiles/image/'+dir+idx+'.jpg';
		*/
	}
}

function showContentImg (dir, content_id, width, height) {
	var img = document.getElementById ('content_img');
	var a = document.getElementById ('content_img_link');
	if (img && a) {
		img.src = dir+'/tb2_'+content_id+'.jpg';
		if (width)
			img.width = width;
		if (height)
			img.height = height;
		a.href=dir+'/tb_'+content_id+'.jpg';
	}
}



function addBasket () {
	var i = 0;
	var fSelected = false;
	for (var i=1;i<100;i++) {
		var radiobutton = document.getElementById ('radiobutton_'+i);
		
		if (radiobutton && radiobutton.checked==1) {
			fSelected = true;
		}
		else
		if (!radiobutton)
			break;
	}
	if (!fSelected) 
		alert ('bitte wählen sie einen artikel aus.');
	else
		document.form1.submit ();
}


function showDeliveryAddress (check) {
	var x = document.getElementById ('delivery_address');

	if (check.checked==1) {
		x.style.visibility = "visible";
		x.style.display = "block";
	}
	else {
		x.style.visibility = "hidden";
		x.style.display = "none";
	}		
}



function showPayType (check, idx) {
	var x = document.getElementById ('pay_type_'+idx);

	if (x && check.checked==1) {
		x.style.visibility = "visible";
		x.style.display = "block";		
	}

	for (var i=1;i<10;i++) {
		if (i==idx)
			continue;
		x = document.getElementById ('pay_type_'+i);
		if (!x)
			break;
		x.style.visibility = "hidden";
		x.style.display = "none";
	}	

}
function showUnregisterNewsletter ()
{
	var obj = document.getElementById('register');
	if (obj) {
		obj.style.display='none';
		obj.style.visibility='hidden';
	}
		
	obj = document.getElementById('unregister');
	if (obj) {
		obj.style.display='block';
		obj.style.visibility='visible';
	}	
	if (document.getElementById ('email')) 
		document.getElementById ('email').focus();
}

// Gallery rotation stuff

galleryUpdater = null;
galleryUpdateCnt = 0;
galleryUpdateMaxCnt = 7;
galleryUpdateTime = 1.5; // sec
galleryUpdateDelayTimer = null;
galleryUpdateDelayTimeout = 500; // ms
galleryIsDelay = false;
galleryWasChanged = false;
updater_supplier_id = 0;
rolloverTimeout = null;
rolloverInterval = null;
rolloverOldDiv = null;

function onGalleryUpdateDalayFinish () {
	galleryIsDelay = false;	
	if (galleryWasChanged) {
		galleryWasChanged = false;
		startRandomGalleryImg (updater_supplier_id, false);
	}
}

function startRandomGalleryImg (supplier_id, ignore_product_id, fCheck) {
	if (fCheck && supplier_id==updater_supplier_id) {
		return;
	}
	
	updater_supplier_id = supplier_id;
		
	if (galleryUpdater) {
		galleryUpdater.stop ();
		galleryUpdater = null;
	}
	
	if (galleryIsDelay) {
		galleryWasChanged = true;
		return;
	}	
	
	galleryUpdateCnt = 0;	
	galleryUpdater = new Ajax.PeriodicalUpdater({success: 'tmp_gallery_img_'+supplier_id}, 
		'random_gallery_img.php?supplier_id='+supplier_id+"&ignore_product_id="+ignore_product_id,
	{
		method: 'get',
		frequency: galleryUpdateTime,
		decay: 1,
		onSuccess: function (originalRequest) { 
			if (galleryUpdateCnt==galleryUpdateMaxCnt)
			{ 
				galleryUpdateCnt=0;				
				if (galleryUpdater) {
					galleryUpdater.stop ();
					galleryUpdater = null;
				}
			}
			galleryUpdateCnt++; 
			if (originalRequest.responseText!='')
				var newDiv = document.createElement ("div");
				newDiv.innerHTML = originalRequest.responseText;
				newDiv.style.position = "absolute";
				newDiv.style.left = "0px";
				newDiv.style.top = "0px";
				newDiv.style.width = "189px";
				newDiv.style.height = "227px";
				
				var container = $('gallery_img_'+supplier_id);

				container.innerHTML = originalRequest.responseText;
		}

	});
	if (galleryUpdateDelayTimer) {
		clearTimeout(galleryUpdateDelayTimer);
		galleryUpdateDelayTimer=null;
	}
	galleryIsDelay = true;
	galleryUpdateDelayTimer = setTimeout(function () { onGalleryUpdateDalayFinish () }, galleryUpdateDelayTimeout);
}

function stopRandomGalleryImg (supplier_id) {
}

function showArtistRollowerImg (product_id) {


	if (rolloverInterval)
	{
		clearInterval (rolloverInterval);
		rolloverInterval = null;
	}

	var e = $('artist_img_rollover');
	imgId = product_id;
	img = new Image ();
	img.src = '/images/product/'+imgId+'.jpg';
	rolloverInterval = setInterval(function () 
	{ 
		if (img.complete) {
			var e = $('artist_img_rollover');
			var div = document.createElement ('div');
			div.className = 'artist_img_rollover_in';

		

			img.style.position='absolute';

			img.style.left='0px';
			img.style.top='0px';
			if (img.width>298) {
				img.style.left = -((img.width-298)/2)+'px';
			}
			else {
				img.style.left = ((298-img.width)/2)+'px';
			}
			if (img.width>199) {
				img.style.top = -((img.height-199)/2)+'px';
			}
			else {
				img.style.top = ((199-img.height)/2)+'px';
			}

			div.id = 'product_img_'+imgId;
			div.appendChild (img);
			
			if (e) {
				e.appendChild (div);

			}
			if (rolloverOldDiv) {
				e.removeChild (rolloverOldDiv);			
				rolloverOldDiv = null;
			}
			
			rolloverOldDiv = div;
			clearInterval (rolloverInterval);
			rolloverInterval=null;
			
		}
	}, 10);				
}




function printIt (obj)
{
	win = 	window.open('', '', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600');
	self.focus();
	win.document.open();
	win.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
	win.document.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">');
	win.document.write('<html>');
	win.document.write('<head>');	
	win.document.write('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">');
	win.document.write('<link rel="stylesheet" type="text/css" href="/css/style_popup.css">');
	win.document.write('</head>');
	win.document.write('<body>');
	win.document.write(obj.innerHTML);
	win.document.write('</body>');
	win.document.write('</html>');	
	win.document.close();
	win.print();
	win.close();
}


