function linkConfirm(message, url)
{
	if(confirm(message)) location.href = url;
}

function confirmSubmit(message)
{
	var agree=confirm(message);
	if (agree)
		return true;
	else
		return false;
}

function getkey(e)
{
	if (window.event)
	   return window.event.keyCode;
	else if (e)
	   return e.which;
	else
	   return null;
}

function goodchars(e, kind)
{
	if (kind == 'num')
		goods = '0123456789';
	
	if (kind == 'alpha')
		goods = 'A¡BCÆDEÊFGHIJKL£MNÑOÓPQRS¦TUWVXYZ¬¯ a±bcædeêfghijkl³mnñoópqrs¶tuwvxyz¼¿';
	if (kind == 'price')
		goods = '0123456789,';
		
	var key, keychar;
	key = getkey(e);
	if (key == null) return true;

	// get character
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
	
	// check goodkeys
	if (goods.indexOf(keychar) != -1)
		return true;
	
	// control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
	   return true;
	
	// else return false
	return false;
}

function popupImage(image, imgWidth, imgHeight)
{
	var new_window;
	var windowX = Math.round((screen.width - imgWidth)/2);
	var windowY = Math.round((screen.height - imgHeight)/2);
	new_window			= window.open('','','toolbar=0,menubar=0,resizable=0,dependent=0,status=0,width='+imgWidth+', height='+imgHeight+', left='+windowX+',top='+windowY);
	new_window.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" /><title>Ottensten</title></head><body onclick="window.close();" style="cursor:pointer;"><img src="http://ott.pl/images/products/large/'+image+'.jpg" alt="" /></body></html>');	
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	
	return s;
}

function margin()
{
	var i = 0;
	var number;
	while (document.basketForm.eval('sale'+i))
	{
		number = 1+(document.getElementById('margin').value / 100);
		number = number * document.getElementById('netto'+i).value;
		number = CurrencyFormatted(number);
		document.basketForm.eval('sale'+i).value = number;
		i++;
	}
}
